JavaScript interview knowledge points and development skills summary

Source: Internet
Author: User
Tags closure

1.bind related usage

Fun.bind (obj) passes obj into the fun as its scope

Fun.bind will return a new function address, fun.bind (obj)!=fun.bind (obj)

Repeated bind only works for the first time

Truth in 2.js

0, "", null, Undefined, false, Nan to Boolean is False

Null = = undefined true

Null = = undefined false

3. Use of expressions

if (a>0)

{

B = True

}

Else

{

B = False

}

should be written as B = a > 0

Complex situations can use local variables or ternary expressions

4. Closures and reference passing

1. All the quotes in the closure are references (simple types are also references!). )

2.for () var defined in the loop is equivalent to the outside defined var i = 0

Let i = 0 should be used for the for () loop so that I is only visible inside the for loop

3. As a result of this closure, you can see that the loop is complete before returning

var methods = []for (var i = 0; i < ten; i++) {    = (function
   
     () {        console.log ("i ="
     , i)        
    return 
     i    })}methods[0
    ] () VM1405: 5 i = 1010
    = 100100
    methods[0
    ] () VM1405:5 i = 100100
   

The following code exposes a critical error in a for-loop error using closures and VAR declaration iterators

varMethods = [] for(vari = 0; I < 10; i++) {Methods[i]= (function() {Console.log ("I =", i)returni})} methods[0] () VM1196:5 i = 1010 for(vari = 0; I < 10; i++) Methods[i] () VM1196:5 i = 0VM1196:5 i = 1VM1196:5 i = 2VM1196:5 i = 3VM1196:5 i = 4VM1196:5 i = 5VM1196:5 i = 6VM1196:5 i = 7VM1196:5 i = 8VM1196:5 i = 99methods[0] () VM1196:5 i = 1010 for(varj = 0; J < 10; J + +) Methods[j] () 10vm1196:5 i = 10

JavaScript interview knowledge points and development skills summary

Related Article

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.