表达式语句

Assignment statements are one major category of expression statements.

The delete operator has the important side effect of deleting an object property.

Function calls are another major category of expression statements.

复合语句和空语句

A statement block is simply a sequence of statements enclosed within curly braces.

{
             x = Math.PI;
             cx = Math.cos(x);
             console.log("cos(π) = " + cx);
         }

First, it does not end with a semicolon. The primitive statements within the block end in semicolons, but the block itself does not.

Second, the lines inside the block are indented relative to the curly braces that enclose them. This is optional, but it makes the code easier to read and understand.

Finally, JavaScript does not have block scope and variables declared within a statement block are not private to the block.

用一个分号可以表示空语句,是否也可以用{}表示空语句呢?

声明语句

var

If a var statement appears within the body of a function, it defines local variables, scoped to that function. When var is used in top-level code, it declares global variables, visible throughout the JavaScript program.

If no initializer is specified for a variable with the var statement, the variable's initial value is undefined.

Note that it is harmless to declare the same variable multiple times.

function

function definition expression:

var f = function(x) { return x+1; } // Expression assigned to a variable

function definition statement:

function f(x) { return x+1; } // Statement includes variable name

Function definitions may not appear within if statements, while loops, or any other statements.

条件语句

if

The rule in JavaScript is that by default an else clause is part of the nearest if statement.

else if

else if is not really a JavaScript statement, but simply a frequently used programming idiom that results when repeated if/else statements are used.

switch

When a switch executes, it computes the value of expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).

循环

while

 

do/while

 

for

 

for/in

属性枚举的顺序

 

跳转

标签语句

break语句

continue语句

return语句

throw语句

try/catch/finally语句

其他类型语句