l--Front-end Development interview knowledge points (JS related)

Source: Internet
Author: User
Tags tag name

1.DOM operations-How do I add, remove, move, copy, create, and find nodes?

1. Create a new node

Createdocumentfragment ()//Create a DOM fragment

CreateElement ()//create a specific element

createTextNode ()//Create a text node

2. Add, remove, replace, insert

AppendChild ()

RemoveChild ()

ReplaceChild ()

InsertBefore ()//Insert a new node in front of existing child nodes

3. Find

getElementsByTagName ()//by tag name

Getelementsbyname ()//value through the Name property of the element

getElementById ()//through element ID, uniqueness

What is the difference between 2.null and undefined?

Null is an object that represents "None" and is 0 when converted to a value;

Undefined is a primitive value that represents "none" and is Nan when converted to a value.

When the declared variable has not been initialized, the default value for the variable is undefined.

Null is used to represent an object that does not already exist, and is commonly used to indicate that a function is attempting to return a nonexistent object.

Undefined means "missing value", that is, there should be a value here, but there is no definition. Typical usage:

1. When a variable is declared but not yet assigned, it is equal to undefined.

2. When calling a function, the parameter that should be supplied is not provided, which equals undefined.

3. The object does not have an assigned property, and the value of this property is undefined.

4. When the function does not return a value, the default return value is undefined.

Null means "No object", that is, there should be no value at all. Typical usage:

1. As an argument to a function, the argument to that function is not an object.

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

What does the 3.new operator do specifically?

1. Create an empty object, and the This variable applies the object, and also inherits the prototype of the function.

2. The properties and methods are added to the object of this application.

3. The newly created object is referenced by this and the last implicit return this.

var obj == base.prototype; Base.call (obj);
4.JSON of understanding?

JSON (JavaScript Object notation) is a lightweight data interchange format. He is based on a subset of JavaScript. Simple data format, easy to read and write, low bandwidth consumption

JSON is a lightweight data interchange format that is ideal for data interchange in a completely language-independent text format. At the same time, JSON is a native JavaScript format, which means that working with JSON data in JavaScript does not require any special APIs or toolkits.

Compared to XML serialization, JSON serialization typically results in smaller data volumes than XML serialization, so JSON is used as a way of exchanging data in well-known websites such as Facebook.

In JSON, there are two kinds of structures: objects and arrays.

1. An object ends with "{" Starting with "}". Each "name" is followed by a ":" and "," (comma) separated by the name/value pair. The name is enclosed in quotation marks, and if the value is a string, it must be enclosed in quotation marks, and the numeric type is not required. Such as:

var obj={"name": "Darren", "age": $, "location": "Beijing"}  

2. An array is an ordered collection of values (value). An array ends with "[" Start, "]". Use "," (comma) to separate values. Such as:

var jsonlist=[{"name": "Darren", "age": +, "location": "Beijing"},{"name": "Weidong.nie", "Age": ":" Hunan "}];

What are the modes of 5.js lazy loading?

Defer and async, dynamically create DOM mode (create script, insert into DOM, load finished callback), asynchronously load JS on demand

6. How do I troubleshoot cross-domain issues?

JSONP, Document.domain + iframe, Window.name, Window.postmessage, set proxy page on server

Detailed principle:l--js cross-domain

The difference between 7.document.write and innnerhtml?

Document.Write can only redraw the entire page

Innnerhtml can redraw part of a page

8.call () and apply () The difference and role?

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

The first parameter of call () is the context, followed by the sequence of arguments passed in by the instance

Function: The environment in which a method of a class is dynamically changed

9. What operations can cause memory leaks?

Memory leak refers to any object that persists after you no longer own or need him.

The garbage collector periodically scans the objects and calculates the number of other objects to which each object is applied. If an object has an applied quantity of 0 (no other object has referenced the object), or if the object's unique reference is circular, then the object's memory is recycled.

The first argument of settimeout uses a string instead of a function, which causes a memory leak. Closures, console logs, loops (a loop is generated when two objects are referenced to each other and reserved to each other)

l--Front-end Development interview knowledge points (JS related)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.