Implement deep copy
○ Shallow copy: Shallow copy refers to copying the attribute value of one object to another object. If the attribute value is a reference type, then the address of the reference is copied to the object, so the two objects will have a reference of the same reference type. Shallow copying can be implemented using Object.assign() and the spread operator. ○ Deep copy: Compared to shallow copy, if a property value is a reference type, deep copy creates a reference type and copies the...
What is the purpose of the newly added primitive data type "Symbol"?
Discuss conceptual questions‘Symbol’ is a primitive data type introduced in ES6. Its primary purpose is to create a unique identifier, which is used in scenarios such as naming object properties, defining constants, and so on. Understanding with Examples Each ‘Symbol’ is unique and can be used as a property name for objects, which helps to avoid conflicts with property names. For example: 1234567const s1 = Symbol();const s2 = Symbol();const obj = { [s1]: 'hello', [s2]:...
What are the differences in asynchronous loading of JS scripts?
What are the differences in asynchronous loading of JS scripts?In Web applications, the asynchronous loading of JavaScript scripts can be achieved in the following ways: a. Dynamically create a tag and set its src attribute to the URL of the script to be loaded. You can use the onload or onreadystatechange event to check if the script has finished loading. 123456const script = document.createElement('script');script.src = 'path/to/script.js';script.onload = function()...
Why is the result of 'typeof null' an 'object'?
Why is the result of ‘typeof null’ an ‘object’?KernelThe result of ‘typeof null’ being “object” is a legacy issue of the JavaScript language. In the original version of JavaScript, a 32-bit value was used to represent a variable, with the first 3 bits representing the type of the value. 000 represents an object, 010 represents a floating point number, 100 represents a string, 110 represents a Boolean value, and other values are all considered pointers. In this representation, null was...
What are the uses of 'requestAnimationFrame' and 'requestIdleCallback', respectively?
‘RequestAnimationFrame’ and ‘requestIdleCallback’ are both APIs used for performing animations or other high-performance tasks in the browser. ‘RequestAnimationFrame’ is a mechanism provided by browsers to request an animation frame. It executes a specified callback function right before the browser’s next redraw. The advantage of this approach is that it allows the browser to automatically perform complex calculations and rendering tasks during the next draw, thus preventing the browser...
Differences among Ajax, axios, and fetch
(1)AJAXAjax stands for “Asynchronous JavaScript and XML.” It’s a way to make web pages interactive without reloading the whole page. Ajax updates parts of a page by fetching a bit of data from the server behind the scenes. This means updates can happen without a full page refresh. Traditional web pages without Ajax need a full reload to update. However, Ajax is not perfect: ● It’s more suited for MVC programming, not quite in line with the front-end MVVM trend. ● Built on the not-so-clear...
Understanding the execution context
Execution context type (1)global execution context Anything that is not inside a function is a global execution context. It first creates a global window object and sets the value of this object to be equal to this global object. A program has only one global execution context. (2)function execution context When a function is called, a new execution context is created for the function. The context of the function can be as many as possible. (3)* * eval * * function execution context ...
The understanding of array-like objects
1、The understanding of array-like objects ,and How to convert them into arrays?An object with the length attribute and several Index attributes can be called a array-like object. Array-like objects are similar to arrays, but array methods cannot be called. Common array-like objects include arguments and DOM methods. Function parameters can also be considered as array-like objects because they contain the length attribute value, which represents the number of parameters that can be received....
Differences between map and weakMap
(1)Mapmap is essentially a set of key-value pairs, but the key in a common Object can only be a string. The Map data structure provided by ES6 is similar to that of an object, but its keys do not limit the range. It can be of any type and is a more complete Hash structure. If the Map key is an original data type, it is considered the same key as long as the two keys are strictly the same. In fact, Map is an array, and each of its data is also an array, with the following format: 1234const...
What happens if you create a new arrow function
The arrow function is introduced in ES6. It does not have a prototype, nor does it have its own this reference, and it cannot use the arguments parameter. Therefore, it is not possible to use the new operator with an arrow function. The steps to implement the new operator are as follows:1.Create a new object Assign the constructor function’s scope to the new object (in other words, set the object’s proto property to point to the constructor function’s prototype property) Point to the...