首页 > 代码库 > 9.3 js基础总结3

9.3 js基础总结3

2.后增量/后减量运算符 ++,--

var i = 10;var a = i++;        // i = i + 1;alert(a);

3.比较运算符(>,<,>=,<=,==,!=,===,!==)

alert ( 10 > 5 );        var i = 100;var n = 100;alert(i == n);    alert(i != n);alert(i === n) 

4.逻辑运算符(&&,||,!)

&&:逻辑与

||:逻辑或

!:逻辑非

var i = 8;     //outputs falsealert ( i<5 && i<10);        //outputs truealert(!(10 > 5));            //outputs false

五、程序流程控制

1.条件语句 if

语法:

if(condition) statements1 else statement2

例:

if(10 > 5) {        alert(“hello world”);    }        var i = 90;    if(i > 100) {        alert(i + “大于100”);    }else if(i > 80) {         alert(i + “大于80”);     }else{         alert(i + “小于100”);     }

2.switch语句

语法:

switch (expression){        case value:            //statement            break;        case value:            //statement            break;        default:            //statement    }

例:

 var i = 25;    switch(i){        case 25:            alert(i + "等于 25");            break;        case 100:            alert(100);            break;        default:            alert(‘other’); }

 

9.3 js基础总结3