1. Pre-parsing related
(function() { console.log (typeof foo); Console.log (typeof bar); var foo = ' Hello ', function() { return ' World '; }; function foo () { return ' Hello '; }} ());
Results:
function undefined
Article Address: http://blogread.cn/it/article/6178
2. Closure related
Code Snippet One:
var name = "the window"; var object ="My object"function() { returnfunction
() { returnthis. Name; }; } }; Alert (Object.getnamefunc () ());
Result: the Window
Code fragment Two:
var name = "the window"; var object ="My object"function() { var This ; returnfunction() { return
Result: My Object
Article Address: http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.html
3. Shallow copy and deep copy
Shallow copy:
function extendcopy (p) { var c = {}; for (varin = p[i];} return C;}
Deep copy:
function deepcopy (P, c) { var c = C | | {}; for (var in p) { if (typeof p[i] = = = 'object ' = (p[ I].constructor = = = Array)? Else { = P[i]; }} return C;}
Shallow copy problem: If the parent object's properties are equal to an array or another object, the child object is actually getting only one memory address instead of a real copy, so there is a possibility that the parent object will be tampered with.
How do you understand bitwise inversion in 4.js?
The Javascript bitwise negation operator (~) performs a bitwise non-(non-negation) operation on an expression. such as to =-2; ~ =-3; Take a look at the calculation steps of the-to:
Turn 1 (call here: Original code) to binary =00000001
bitwise inverse =11111110
The discovery sign bit (that is, the highest bit) is 1 (for negative numbers), and the number other than the sign bit is reversed =10000001
The bottom plus 1 takes its complement =10000010
Convert Back to decimal =-2
The arithmetic rules of bitwise negation so strange is not unique to JavaScript, but to all computer languages. The main reason for this is that in order to unify subtraction and addition, in the computer, subtraction becomes a negative number, and negative numbers are stored in the form of complement. And this is mainly because the complement and the number of decimal number has such a conversion relationship, negative: 补码(x) = -x - 1
, positive: 补码(x) = x
.
For reference: Binary How to go to decimal, decimal how to Binary
Problem Address: https://segmentfault.com/q/1010000005697515
5.javascript Syntax tag (label)
The JavaScript language allows the statement to be preceded by a label (label), which is equivalent to a locator that jumps to any location in the program, and the label is formatted as follows.
Label: statement
The label can be any identifier, but it cannot be a reserved word, and the statement part can be any statement.
Tags are typically used in conjunction with break statements and continue statements to jump out of a specific loop.
Top: for (var i = 0; i < 3; i++) { for (var j = 0; J < 3; J + +) { if
break top; Console.log (' i= ' + i + ', j= ' + j); } } // i=0, J=0 // i=0, J=1 // i=0, j=2 // I=1, J=0
The code above is a double loop block, and the break command is followed by the top tag (note that top does not have to be quoted), and when the condition is met, it jumps directly into the double loop. If you do not use a label after the break statement, you can only jump out of the inner loop and into the next outer loop.
Continue statements can also be used in conjunction with tags.
Top: for(vari = 0; I < 3; i++){ for(varj = 0; J < 3; J + +){ if(i = = 1 && j = = 1)Continuetop; Console.log (' i= ' + i + ', j= ' +j); } }//i=0, J=0//i=0, J=1//i=0, j=2//I=1, J=0//i=2, J=0//i=2, J=1//i=2, j=2
In the above code, the Continue command is followed by a label name that, when satisfied, skips the current loop and goes directly to the next outer loop. If you do not use tags after the Continue statement, you can only enter the next round of inner loops.
Description
Both the break statement and the continue statement have a jump effect, which allows the code to be executed in an existing order.
The break statement is used to jump out of a code block or loop.
The continue statement terminates the loop immediately, returning to the head of the loop structure and starting the next round of loops.
"Summary" interesting web front-end articles or topics (V)