- What are the data types
- Value types: String, Number, Boolean, Null, Undefined, Symbol.
- Reference data types: Object, Array, Function.
- Note: Symbol is a new primitive data type introduced in ES6 that represents unique values.
Reference data types: Object, Array, Function.
Note: Symbol is a new primitive data type introduced in ES6 that represents unique values.
-
What are closures and why are they used
- Closures are functions that can read variables inside other functions
- In JS, only subfunctions inside functions can read local variables, so closures can be simply understood as “functions defined inside a function”. In essence, closures are a bridge between the inside of a function and the outside of a function
- Benefit 1: Reads variables inside a function
- Benefit 2: Keep the values of these variables in child memory and reuse variables without global contamination
-
this
- Why use this:
- This provides a more elegant way to implicitly “pass” an object reference, so the API can be designed to be more compact and easy to reuse. As code usage patterns get more complex, explicitly passing context gets messier, not so with this, because the function automatically references the appropriate context object!
- What is this?
- When a function is called, an active record (sometimes called the execution context) is created. This record contains information about where the function was called (call stack), how the function was called, the parameters passed in, and so on. This is an attribute of the record that is used during function execution.
- What are the binding rules for this:
- 1 Default Binding
- 2 Implicit binding
- 3 Explicit binding
- 4 new binding
- Priority: 4 > 3 > 2 > 1
- Binding exception:
- Ignored this(null, undefined)
- Indirect reference (assignment)
- Arrow functions: Instead of using the 1-4 binding rules, this is scoped, meaning that the arrow function inherits the this binding of the outer function (whatever this is bound to).
- Why use this:
-
Prototype | import | the require
-
What exactly happens when you new an object
-
Synchronous asynchronous
-
Js an array of add and delete | localStorage | cookies
-
Get vs. Post
-
How do native JS prevent bubbling events
-
ES5 ES6 to heavy
-
var a = 3; And a = 3
-
var a = Object(); a.value = 1; b=a; b.value=2; console.log(a.value); / / 2Copy the code
-
How do native JS prevent bubbling events
- The sample
Property or event name instructions compatibility Cancelable properties The cancelable event returns a Boolean value. True if the event preventDefault() method undoes the default action associated with the event, fasle otherwise IE does not support The returnValue property If this property is set, its value takes precedence over the return value of the event handle. Setting this property to fasle cancels the default action for the source element where the event occurred. IE only Bubbles properties The Bubbles event property returns a Boolean value, true if the event is of the bubbling type, fasle otherwise. IE does not support StopPropagation method No more events are sent. Further propagation of an event in the capture, target processing, or bubbling phases of propagation. When this method is called, the handler that handles the event on that node is called, and the event is no longer dispatched to another node. – The preventDefault method Cancels the default action for the event. Note that if the Cancelable attribute of the Event object is fasle, there is no default action, or the default action cannot be blocked. In either case, calling this method has no effect. – -
The difference between POST GET requests
project get post Back button/refresh harmless Data will be resubmitted (browsers should inform users that data will be resubmitted) The cache Can be cached Can’t cache history Parameters are retained in browser history Parameters are not retained in browser history A limit on the length of data There are limits. When sending data, the GET method adds data to the URL; URL length is limited (maximum LENGTH of URL is 2048 characters). unlimited Restrictions on data types Only ASCII characters are allowed Binary data is also allowed without restrictions security Security is low and the data sent is part of the URL Security is high because parameters are not saved in browser history or Web server logs Data visibility The data is visible to everyone in the URL The data is not displayed in the URL -
Js add, delete, or modify an array
- Create:
var arr = new Array()
- Add:
arr[0] = '0'; arr[1] = '1'; Copy the code
- Modification:
arr[0] = 'test'; Copy the code
- Delete:
arrayObject.splice(index,howmany,item1,..... ,itemX)Copy the code
- Common array operations
- Create: