abstract boolean byte char class const debugger double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile
运算符
算数运算符
1
+-*/% ++ --
比较运算符
1
> >= < <= != == === !==
注意:
1 2
1 == "1" // true 1 === "1" // false
逻辑运算符
1
&& || !
赋值运算符
1
= += -= *= /=
流程控制
if-else
1 2 3 4 5 6
var a = 10; if (a > 5) { console.log("yes"); } else { console.log("no"); }
if-else if-else
1 2 3 4 5 6 7 8
var a = 10; if (a > 5) { console.log("a > 5"); } elseif (a < 5) { console.log("a < 5"); } else { console.log("a = 5"); }
switch
1 2 3 4 5 6 7 8 9 10 11
var day = newDate().getDay(); switch (day) { case0: console.log("Sunday"); break; case1: console.log("Monday"); break; default: console.log("...") }
switch中的case子句通常都会加break语句,否则程序会继续执行后续case中的语句。
for
1 2 3
for (var i=0;i<10;i++) { console.log(i); }
while
1 2 3 4 5
var i = 0; while (i < 10) { console.log(i); i++; }