js Simple Tips

1. javascript typeof return of which data types:

   string, boolean, number, undefined, function, object

() Difference 2. split join () of

   The former is an array of strings is cut, which is to convert the array into a string

3. ajax request when, how to parse data json

       Use JSON.parse

4. What event delegates are?

  Using the principle of event bubbling, so that their event is triggered, so that his place of execution of the parent element! 

5. Create a new node
createElement () // create a concrete element
createTextNode () // Create a text node

6. Add, remove, replace, insert
appendChild () // add
removeChild () // removing
The replaceChild () Alternatively //
insertBefore () // insert

3) Find
the getElementsByTagName () // tag name through
the getElementsByName () // a value of the name attribute of the element
the getElementById () // by elemental Id, uniqueness

7. Explain jsonp principle, and why not real ajax

Create a dynamic script tag, the callback function
Ajax is no page refresh request data manipulation

8. document load and distinction of document ready

   document.onload in structure and style, as well as image loading external js execution until they have finished js
   document.ready is to create a dom tree to complete the implementation of the method, this method is not native species, jquery have $ (). ready (function)

 

9. The difference between null and undefined?

  null is represented by a "no" of the object, when the converted value is 0; undefined is represented by a "no" to the original value, when converted to a NaN value.

 When the variable declaration has not been initialized, the default variable is undefined. null means object does not exist yet

  undefined said that "lack of values" is here should have a value, but has not been defined. Typical usage is:

(1) variable is declared, but no assignment, it means undefined.

(2) function is called, the parameters should be provided is not provided, the parameter is equal to undefined.

(3) the object attribute is not assigned, the value of the attribute undefined.

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

   null means "no object", that is, there should not have value. Typical usage is:

(1) as a parameter, a parameter indicating the function is not an object.

(2) as an endpoint object prototype chain.

 10. js lazy loading options?

         and defer the async, dynamically created DOM embodiment (Script created, is inserted into the DOM, callBack After completion of the loading), the asynchronous load demand js

11. want to get into the page all the checkbox how to do? (Do not use third-party frameworks)

     var inputs = document.getElementsByTagName ( "input" ); // get all of the input label object
     var checkboxArray = []; // initializes an empty array used to store objects checkbox.
     for (var I = 0; I <inputs.length; I ++) {
    var obj = Inputs [I];
    IF (obj.type == 'CheckBox') {
   checkboxArray.push (obj);
  }
  }

12. How to obtain the maximum and minimum number of three javascript?

   Math.max (a, b, c); // maximum

  Math.min (a, b, c) // minimum

 13.  

Data types include three main javaScript, the two kinds of complex data types and two special data types.

The main data types: string, boolean, number

Complex data types: function, object

Special types: undefined, null

14.

Explain what Json:

(1) JSON is a lightweight data-interchange format.

(2) JSON is independent of language and platform, JSON parser and JSON library supports many different programming languages.

(3) JSON syntax value represents three types, simple values ​​(strings, numbers, Boolean values, null), arrays, objects

14. js in three kinds of pop-up message alerts (warning window, the confirmation window, information input window) imperative What?
         Three kinds of pop-up box

   // Common popup 
// first popup
// Alert ( "hello ~")

// input box: accepting user input as a string;
var info = prompt ( "Please enter Content ~");
Console .log (info);

// confirmation box: select the user to confirm or cancel, get true | false two Boolean result
var res = confirm ( "? you are a pig it");
console.log (RES);

15.  

 Benefits closures

(1) want a long-term presence in the variable memory of them (not to be garbage collection mechanism)

(2) avoid contamination global variables

The presence of (3) private members

(4) improve security

 

Guess you like

Origin www.cnblogs.com/xiaozhaung/p/10948153.html