There are few opportunities to contact algorithms in the front end, most of them are interactive operations, but from the perspective of the interviews of major companies, algorithms are still one aspect of investigation. The following article gives you a summary of the common test questions in the front-end JS interview, there is a need for friends to refer to, let’s have a look at it.
preface
Learning data structures and algorithms helps engineers understand and analyze problems. If we are faced with complex problems in the future, the accumulation of these basic knowledge can help us better optimize our solutions. Here are some of the most common questions you may encounter in a front-end interview.
1. Introduce the basic data types of JS
Undefined, Null, Boolean, Number, String
2. What built-in objects does S have?
Data encapsulation class objects: Object, Array, Boolean, Number, and String
Other objects: Function, Arguments, Math, Date, RegExp, Error
3. Understanding of this object
This always refers to the direct (not indirect) caller of the function;
If we have the new keyword, this refers to the object that came out of new;
In an event, this points to the object that triggered the event. In particular, this in an attachEvent in IE always points to the global object Window;
What does Eval do?
Its function is to parse the corresponding string into JS code and run;
Eval should be avoided as it is unsafe and very performance-intensive (2 times, once parsed into JS and once executed).
Var obj =eval(‘ (‘ + STR + ‘) ‘);
5. How does DOM add, remove, move, copy, create, and find nodes
// Create a node
CreateDocumentFragment () // Create a DOM fragment
CreateElement () // Create a specific element
CreateTextNode () // Create a text node
// Add, remove, replace, insert
appendChild()
removeChild()
replaceChild()
InsertBefore () // Inserts a new child before an existing one
/ / to find
GetElementsByTagName () // Pass the tag name
GetElementsByName () // Pass the value of the element’s Name attribute.
GetElementById () // Unique by element Id
6. Null vs. undefined
Null is an object representing “none” and is zero when converted to a value; Undefined is a primitive value for “none”, which is NaN when converted to a value.
Undefined:
(1) If a variable is declared but not assigned, it is undefined.
(2) When the function is called, the argument that should be provided is not provided, which is equal to undefined.
(3) The object has no assigned attribute. The value of this attribute is undefined.
(4) If the function does not return a value, undefined is returned by default.
Null:
(1) as the parameter of the function, indicating that the parameter of the function is not an object.
(2) as the end of the object prototype chain.
7. What exactly does the new operator do?
(1) Create an empty object, and the this variable references the object and inherits the prototype of the function.
(2) Attributes and methods are added to the object referenced by this.
(3) The newly created object is referenced by this and implicitly returns this.
8. What about JSON?
JSON(JavaScript Object Notation) is a lightweight data interchange format. It is based on a subset of JavaScript. The data format is simple, easy to read and write, and occupies little bandwidth.
Format: key-value pairs, e.g. {‘ age ‘:’ 12 ‘, ‘name’ : ‘back’}
9. What is the difference between call() and apply()?
The apply() function takes two parameters: the first is the context, and the second is an array of parameters. If the context is NULL, a global object is used instead.
Such as: the function. The apply (this, [1, 2, 3]);
The first argument to call() is the context, followed by the sequence of arguments passed in by the instance.
Such as: the function call (this, 1, 2, 3);
10. How to obtain UA?
function whatBrowser() {
document.Browser.Name.value=navigator.appName;
document.Browser.Version.value=navigator.appVersion;
We recommend a free learning group, which summarizes mobile application website development, CSS, HTML, Webpack, Vue Node Angular and interview resources, etc. Students interested in web development technology, welcome to join Q group: 864305860, no matter you are small white or Daniel I welcome, and Daniel organized a set of efficient learning routes and tutorials to share with you free, while updating video materials every day. In the end, I wish you all success as soon as possible, get satisfactory offer, fast promotion and salary increase, and walk on the peak of life. document.Browser.Code.value=navigator.appCodeName;
document.Browser.Agent.value=navigator.userAgent;
}