This article summarizes the commonly used knowledge in JS, some almost do not use, or belong to the design flaw, but must know, these are my development summary, if there is incorrect place, please point out.
Personal code habits sharing: Naming as far as possible semantic but more special, this will avoid naming conflicts, even if the global local variables will belong to different domains and do not use the same name, a little longer okay, not very English how to do? Pinyin!
A. Variable
1.) in non-strict mode, global variables can be used directly without Var, but this is not good, will cause ambiguity, reading will be difficult. So the formal wording is in advance declaration.
2.) There is a concept called variable promotion, within the function, all variables will be promoted to the upper part of the function body declaration.
function Upvar () {console.log (x); var x = 0;} Upvar ();//print undefined
Variable declaration after printing, even in strict mode will not error, because the JS mechanism to advance the variable declaration to the first line of the function body, but not assigned value, so the above function is equivalent to:
function Upvar () {var x;console.log (x); x = 0;} Upvar ();//print undefined
So what if the global variable has the same name as a local variable inside the function? The result is the same. The function first scans the inner function.
var a = 2;function Samenamea () {Console.log (a) var a = 3;} Samenamea ();//print undefined
Variable use must be declared in advance and must be assigned in advance before use. So in my opinion, unless the brain cramps, I will not write this code. Belong to remember the concept can.
3.) This point
At the global scope, this is a pointer to the window, which means you can use this. The variable calls the global variable, this. function calls the global function.
Within the object, point to the current object.
Within the event, point to the event Dom.
Two. Data type
1.) JS has v basic type, a reference type
Base type: String,boolean,number,undefind,null
Reference type: Object (date,array,reg,function)
Basic Package Type:
Monomer built-in objects:
The base type is a simple value, what you see is what you get, the reference type is a complex type, and its value is calculated.
2.) type built-in function
String
Wait More ...
Javascript Centralized Knowledge Reserve