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