-
What are the JS data types? How are they stored?
- JS has eight data types
- 7 basic data types: undefined, NULL, Booblean, Number, String, symbol (es6 new), bigINT (ES10 new)
- One reference data type: Object, including function, object and array
- How to store
- Basic data types are stored on the stack, take up small space, and are fixed in size
- Reference data types are stored in stacks and heaps, taking up large space and varying sizes. A reference data type stores a pointer on the stack to the starting address of the entity in the heap. When the interpreter looks for a reference value, it first retrieves its address in the stack and then retrieves the entity from the heap.
- JS has eight data types
-
How is inheritance implemented in ES5? What are the ways inheritance is implemented?
-
What is the difference between a base data type and a reference data type?
-
The basic data type is accessed by value. After copying between variables, modifying one of them does not affect the value stored by other variables.
-
Reference data types are objects stored in the heap. Unlike other languages, you cannot directly access locations in the heap memory space and manipulate the heap memory space. Only reference addresses of objects on the stack can be manipulated.
-
The difference between
- Different memory space allocated when declaring variables;
- Different access mechanisms
- The reference type only copies the address pointer of the variable in the stack. The same entity is used in the heap, which can be understood as copying the variable has one more entity reference of the pointer in the stack.
- Arguments are passed differently: First we should make it clear that arguments to all functions in ECMAScript are passed by value. For a reference type variable, the function passes a reference to the entity that the variable is stored on the stack.
-
-
What is the prototype chain?
-
Talk about scope?
-
What do you know about this?
-
What are the methods of object traversal in JS?
- for… In loops over the object’s own and inherited enumerable properties (excluding Symbol properties). .
- Keys () traverses (returns an array containing all of the Object’s own (not inherited) enumerable properties (not Symbol).) .
- Object. GetOwnPropertyNames (obj), and returns an array that contains all attributes of the Object itself (excluding Symbol attribute, but cannot be enumerated attribute).
- Reflect.ownkeys (obj) traversal returns an array containing all the properties of the object itself, regardless of whether the property name is Symbol or string or enumerable.
- Object. GetOwnPropertySymbols () method returns an array of Symbol attribute of the Object itself, not including string attribute
-
What are the methods of array traversal in JS?
- The for loop
- Foreach loop, notice that it takes three arguments
- Map loop, notice that there are three parameters
- Forof traversals respond correctly to break, continue, and return statements
- Filter traversal does not alter the original array and returns the new array
- Every () runs the given function on each item in the array, and returns true if the function returns true for each item.
- Some () runs the specified function on each item in the array, returning true if the function returns true for any item.
- Reduce takes a function with four parameters: the last value, the current value, the index of the current value, and the array
- The function of the reduceRight() method is the same as that of reduce(), except that reduceRight() adds the items in the array forward from the end of the array.
- The find() method returns the first element in the array that matches the criteria of the test function. Otherwise return undefined
- For each element in the array, the findIndex method calls the callback once (in ascending index order) until any element returns true. As soon as one element returns true, findIndex immediately returns the index of the element that returns true. If no element in the array returns true, findIndex returns -1. FindIndex does not change the array object.
- ES6 provides three new methods — entries(), keys() and values() — for traversing groups of numbers. They both return a traverser object, which can be used for… The of loop is traversed, the only differences being that keys() is traversal of key names, values() is traversal of key values, and entries() is traversal of key value pairs
-
What are the common methods of JS arrays?
- Push, add a new element to the end of the array
- Pop, removes an element at the end of the array and returns that element
- Shift removes the first element in the array header and returns that element
- Unshift adds an element to the head of the array and returns the array
- Concat, array concatenation
- Join, where array elements are converted to strings separated by parameters
- ToString, array elements are converted to strings
- The split,
- Reverse, the array is in reverse order
- Sort, array sort
- Slice (start,end), returns the specified element of the array
- splice(index,howmany,item1,….. ,itemX), delete the element and add the new element
-
What about variable promotion?
-
JS accuracy loss problem?
-
Typical problem of JS precision loss
- Floating point addition
0.1 + 0.2! = 0.3 / / trueCopy the code
- Large integer operation
9999999999999999 == 10000000000000001 // true Copy the code
- ToFixed does not round
1.335. ToFixed (2) / / 1.33Copy the code
-
JS precision loss causes the computer’s binary implementation and bit limits Some numbers cannot be represented finitely. Just like some irrational numbers cannot be expressed in a finite way, such as PI 3.1415926… , 1.3333… And so on. JS complies with IEEE 754 specification, adopts double precision storage, occupying 64 bit.
-
Solution zhuanlan.zhihu.com/p/100353781 accuracy loss
-
-
How do you handle binary data in JS? (Bluetooth communication, etc.)
-
Point!! What about asynchronous JS programming solutions?
-
Point!! What’s your understanding of Promise? How to fulfill a Promise? How do I implement the promise.all method?
-
How does the CO library work?
-
What is strict mode? How is it different from normal mode?
- Makes Javascript run under more stringent conditions.
- Strict mode makes some changes to the syntax and behavior of Javascript
-
Global variables are explicitly declared
In normal mode, if a variable is assigned without a declaration, the default is global. Strict mode forbids this use, and global variables must be explicitly declared.
-
Static binding
(1) Forbid the use of the with statement
(2) Create eval scope
-
Enhanced security measures
(1) Disallow this keyword from pointing to global objects
``` function f(){ return ! this; } // Return false because "this" refers to the global object, "! This "is false function f(){"use strict"; return ! this; } // return true, because strictly this is undefined, so "! This "to true.Copy the code
(2) Forbid traversing the call stack inside a function
-
Disallow variable deletion
Variables cannot be deleted in strict mode. Only the object property with the 64X set to true can be deleted
-
Explicit error
In normal mode, assigning a read-only property to an object does not report an error, but silently fails. In strict mode, an error is reported.
In strict mode, an error is reported when assigning a value to a property read using a getter method.
In strict mode, an error is reported when adding a new attribute to an object for which extension is prohibited.
In strict mode, an error is reported when an attribute that cannot be deleted is deleted.
-
The nuptial error
(1) Objects cannot have identical attributes
(2) Functions cannot have arguments with the same name
-
Disallow octal notation
-
Arguments object limits
-
Functions must be declared at the top level
-
Added a batch of reserved words
-
-
What are the common methods for string and array?
-
Have you used closures? What are the use scenarios for closures? How to use closures properly?
-
Have you used extension operators?
-
Have you used Proxy and Reflect?
-
What do you understand about Generator functions?
-
Have you used ES6 Class before? How is inheritance different from ES5 implementation?
-
What does ES6 extend ES5? (Functions, arrays, objects, operators)
- Arrow function
- Template string
- Block-level scope
- The default parameters
- Class definition and inheritance
- for… Of the operator
- Expansion operator
- Promise
- Module export and import
-
IIFE is an immediate call function expression
-
Symbol use scenario?
-
What are the benefits of using spread syntax in ES6? How is it different from residual (REST) syntax?
-
What is the difference between call, apply and bind?
-
What are variable promotion and function promotion?
-
A temporary dead zone?
-
What is the difference between Map and weakMap?
-
Do you know anything about coriolization?
-
Shallow and deep copies of JS objects?