JavaScript front end face questions personal summary

1, JS What type of data

  • The main data types: Undefined , Null , Boolean , Number The, String
  • Reference data types: object, array, function

2, JS composition

  • ECMAScript (core): JavaScript Language Basics
  • DOM (Document Object Model): specifies the interface for accessing HTML and XML
  • BOM (Browser Object Model): provides objects and methods of interaction between the browser window

3, which describes the JS built-in objects

  • Package data class object: Object, Array, Boolean, Number, String
  • Other objects: Function, Arguments, Math, Date, RegExp, Error
  • ES6 new objects: Symbol, Map, Set, Promises, Proxy, Reflect

4, JS in the understanding of this point and

Called Non-strict mode Remark
Ordinary function call window In strict mode is undefined
The constructor calls Examples of objects that are created The method of this prototype is the object instance
Object method calls This method belongs to the object Next object
Event binding method The object that triggered the event
Timer function window

5, the difference between null and undefined?

  • null is represented by a "no" of the object, when the converted value is 0;
    • As a parameter, a parameter indicating the function is not an object.
    • As the end point object prototype chain.
  • It is undefined showing a "no" in the original value, when converted to a NaN value.
    • Variable is declared, but no assignment, it means undefined.
    • When you call the function, the parameters should be provided not provided, this parameter is equal to undefined.
    • No attribute assignment target value of the attribute undefined.
    • When the function does not return a value, the default returns undefined.

Note: null == undefined result is a true, null === undefined is the result of false.

6. What is a memory leak, which actions will cause a memory leak

  • Memory leak: refers to an allocated memory we can not use, it can not recover until the end of the process browser

  • Operation may cause a memory leak:
    • Unexpected global variables
    • Closure
    • Circular references
    • Forgotten or timer callback function

7, export and export default What is the difference

  • export and export default can be used to derive constants, functions, files, modules, etc.
  • In a file or module export, importthere may be a plurality, export defaultonly one
  • By exportway of deriving, when introduced to increase { }, export defaultthere is no need
  • Use export defaultthe command, specify the default output modules, so you do not need to know the name of the variable to load modules; exportload time need to know the name of the variable load module
  • export defaultThe nature of the command is to back the value assigned to defaultthe variable, so you can directly write a value in export defaultafter

8, JS how to add, remove, replace, insert, copy, create and find nodes

  • Add, remove, replace, insert before, after insertion, duplication

    appendChild()
    
    removeChild()
    
    replaceChild()
    
    insertBefore()
    
    insertAfter()
    
    cloneNode() 
  • Create a new node

    createDocumentFragment() //创建一个DOM片段
    createElement() //创建一个具体的元素
    createTextNode() //创建一个文本节点
  • Find new node

    document.getElementsByTagName("")    //通过标签名称
    document.getElementsByName("")    //通过元素的Name属性的值
    document.getElementById("")    //通过元素Id,唯一性
    document.getElementsByClassName("");  //通过类查找
    document.querySelector("")  //通过选择器

9, compare typeof and instanceof?

The same point: JavaScript and the instanceof typeof used to determine whether a variable is empty, or what type.

  • Definitions and Usage typeof: return value is a string, for explaining the data type of the variable.
    • Usually only a few typeof returns the following results: number, boolean, string, function, object, undefined.
    • typeof to obtain a variable exists, such as if (typeof a! = "undefined") {alert ( "ok")}, rather than going to use the IF (a) because if a is not present (not declared) error occurs.
    • For Array, Null objects and other special use all return typeof object, which is typeof limitations.
  • Instanceof Definition and Usage: instanceof a variable for determining whether an object instance.

    a instanceof b?alert("true"):alert("false"); //a是b的实例?真:假
    
    var a = new Array(); 
    alert(a instanceof Array);  // true
    alert(a instanceof Object)  // true
    如上,会返回 true,同时 alert(a instanceof Object) 也会返回 true;这是因为 Array 是 object 的子类。
    
    function test(){};
    var a = new test();
    alert(a instanceof test)   // true

10, how to understand the closure function?

  • Is a function of the external variables can call a function inside a function definition,
  • That is, when the return value is a function of another function, and that if the called function returns the inside of the other variables of its parent function, if the return of this function is performed externally, it creates a closure.
  • Characteristics closure package:
    • Then nested functions within a function
    • Internal parameters and variables can be referenced function of the outer layer
    • Parameters and variables will not be garbage collection mechanism

11, the difference between synchronous and asynchronous Ajax

AJAX based on the value of the async divided into synchronous (async = false)and asynchronous (async = true)two execution methods; recommended executed asynchronously W3C tutorial; default asynchronous (true)

  • Asynchronous: Regardless ajaxof the execution of the request has not returned, the code will continue down, like two threads executing the same time.
  • Synchronization: Only ajaxafter the completion of the request to return data code to proceed down like the same single-threaded.

12, tell us about the basic features of the ES6

ECMAScript 6.0It is JavaScriptthe next-generation standard language

  • Declare a variable manner let,const
  • Deconstruction variable assignment
  • Add string method includes(), startsWith(), endsWith()and the like
  • New array methods Array.from(), Array.of(), entries(), keys(), values(), etc.
  • Object concise writing and new methods Object.is(), Object.assign(), entries(), keys(), values(), etc.
  • SymbolPrimitive data types
  • Arrow functions, restparameters, functions and other parameters default values
  • The new data structure: SetandMap
  • ProxywithReflect
  • PromiseObjects, asynchronous programming a solution
  • GeneratorFunction yieldcommands and asyncfunctions awaitcommand
  • ClassUsage class
  • Module Loading modules and output system

Guess you like

Origin www.cnblogs.com/wangchangli/p/11247718.html