Home  >  Article  >  Web Front-end  >  The latest spring interview in 2019 - JavaScript classic interview questions

The latest spring interview in 2019 - JavaScript classic interview questions

云罗郡主
云罗郡主Original
2019-02-15 14:43:094670browse

The latest spring interview in 2019 - JavaScript classic interview questions

php Chinese website has compiled 10 JavaScript interview questions. Come and test whether you have mastered all the core JavaScript skills. You can definitely use them in the interview.

Recommended related articles:The most complete collection of js interview questions in 2020 (latest)

1Introducing the basic data types of js

Undefined, Null, Boolean, Number, String

2What are the built-in objects of js?

Data encapsulation class objects: Object, Array, Boolean, Number and String

Other objects: Function, Arguments, Math, Date, RegExp, Error

3this Understanding of objects

this always points to the direct caller of the function (not the indirect caller);

If there is a new keyword, this points to the object that came out of new;

In the event, this points to the object that triggered the event. Specially, this in the attachEvent in IE always points to the global object Window;

4What does eval do?

Its function is to parse the corresponding string into JS code and run it;

You should avoid using eval, which is unsafe and very performance-consuming (twice, once parsed into js statement, executed once).

When converting from JSON string to JSON object, you can use eval, var obj =eval('(' str ')');

5How to add, remove, Move, copy, create and find nodes

//Create new nodes

createDocumentFragment() //Create a DOM fragment

createElement() //Create a Specific elements

createTextNode() //Create a text node

//Add, remove, replace, insert

appendChild()

removeChild ()

replaceChild()

insertBefore() //Insert a new child node before the existing child node

// Search

getElementsByTagName() //By the tag name

getElementsByName() //By the value of the Name attribute of the element (IE has strong fault tolerance, you will get an array, including the id equal to the name value)

getElementById() //Uniqueness through element Id

6The difference between null and undefined?

null is an object that represents "none" and is converted to a numerical value is 0; undefined is a primitive value representing "none", and is NaN when converted to a numerical value.

undefined:

(1) When the variable is declared but not assigned a value, it is equal to undefined.

(2) When calling the function, the parameter that should be provided is not provided, and the parameter is equal to undefined.

(3) The object has no assigned attribute, and the value of this attribute is undefined.

(4) When the function does not return a value, it returns undefined by default.

null:

(1) As a parameter of the function, it means that the parameter of the function is not an object.

(2) As the end point of the object prototype chain.

7What exactly does the new operator do?

(1) Create an empty object, and the this variable refers to the object, and also inherits the prototype of the function .

(2) Properties and methods are added to the object referenced by this.

(3) The newly created object is referenced by this, and this is returned implicitly at the end.

8What do you know about JSON?

JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of JavaScript. The data format is simple, easy to read and write, and takes up little bandwidth.

Format: using key-value pairs, for example: {'age':'12', 'name':'back'}

9The difference between call() and apply() And the function?

apply() function has two parameters: the first parameter is the context, and the second parameter is an array of parameters. If the context is null, the global object is used instead.

For example: function.apply(this,[1,2,3]);

The first parameter of call() is the context, and the subsequent parameter sequence is the parameter sequence passed in by the instance.

For example: function.call(this,1,2,3);

10How to get UA?

function whatBrowser() { 
     document.Browser.Name.value=navigator.appName; 
     document.Browser.Version.value=navigator.appVersion; 
     document.Browser.Code.value=navigator.appCodeName; 
     document.Browser.Agent.value=navigator.userAgent; 
 }

Related learning Recommended: javascript video tutorial

The above is the detailed content of The latest spring interview in 2019 - JavaScript classic interview questions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use trunc functionNext article:How to use trunc function