The statement is the JavaScript whole sentence and the command.
An expression statement:
count++; alert (123); A = 100; .......
Compound statement and empty statement:
A compound statement is a compound statement that connects multiple statements together with commas. {X=1;y=2;alert (x); alert (y)}
PS: There are no block-level scopes in Javscript, only function scopes.
An empty statement contains 0 statements, which are also useful in some cases.
such as for (var i = 0; i < 3; a[i++] =0); In this case, the end is a semicolon that executes the statement inside the for loop parenthesis.
Statement statement:
var declares a variable.
If Var is declared within a function scope, then the variable is a local scope.
PS: Variable has a problem with advance declaration in function scope
function () { var b = "Hello World"; function A () { console.log (b); // variable advance declaration, undifined var b = "World Hello"; // because variable b is defined here, it causes the variable to be declared in advance. Console.log (b); } Console.log (b); A ();}
In the above code, the function a first outputs B, but B is not declared before, but after B there is a declaration b= "World Hello", according to the variables in the function scope Advance declaration of the rules, then var = b will advance to the top of the function block, so the first console.log (b) For undifined.
function definition functions, you must use curly braces, even if it is a statement, do not omit curly braces.
var a = function () {} functions define expression mode
How function A () {} functions are declared
There are differences between the two ways to define a function:
After the first expression is defined, the variable declared by VAR will advance to the top of the scope, but the function block is still in place, so if the function is called above the function block it will be an error.
The second function is declared after the declaration, the variables and function blocks are advanced to the top of the scope, you can do the context, so call the function on the function block can be used normally.
Window.onload =function() {alert (b ()); //"World Hello"Alert (A ());//uncaught typeerror:a is not a function //in the function expression, only the variable declaration is advanced, and the variable initialization code is still in its original position . varA =function(){ return"Hello World"; } //function declaration statement, function name and function body are advanced, you can call it before declaring functionB () {return"World Hello" } }
Conditional statements:
If else if switch
If expression in statement if must be written, statement is also a statement that must be written.
Switch can handle multiple branches of the case
switch (expression) {
Case (expression):
Statement
Break
...........
Default:
Statement
Break
}
If there is no break in switch, the statement is executed until the last statement of the switch.
You can replace break with return in the function.
Case matching is compared by using "= = =", so the type conversion is not performed when the match is made.
The switch is compared from top to bottom, and default can be placed in any position.
Cycle
While do/while for for/in
Do/while a loop that executes at least once, do executes the statement first, and then it passes the while to judge
For/in is used to traverse the properties of an object.
For (variable in object), even if object is a primitive value, it is also converted to a wrapper object to traverse.
But traversal is also conditional, can only traverse enumerable properties, and JavaScript core methods and object properties are non-enumerable, so there is no way to traverse the traversal, and their own definition of the object properties and methods can be traversed.
If the for/in loop body is deleted when it has not been traversed to a property, then this property will not be acquired, and if an attribute is added to the for/in loop body, it will not be acquired.
The order of property enumerations, generally enumerated by the order in which the attribute is defined.
JavaScript Learning notes--statements