1. 比较运算符
==(值相等,类型可以不等), ===(值和类型必须都相等), !=, >, <, >=, <=
2. 逻辑运算符
&&、||、!
3. 条件运算符
(condition)?value1:value2
<script> //比较运算符 ==, ===, !=, >, <, >=, <= var x = 5; var s = "5" if(x==s) { document.write("测试=="+"</br>"); //值相等,类型可以不相同 } var y = "5" var z = "5"; if(x===s) { document.write("===和==一样" + "</br>"); } if(y===z) { document.write("测试===" + "</br>");//要求值和类型必须都相等 } //条件运算符 var visitor="Pres"; document.write((visitor == "Pres") ? "Dear President" : "Dear Sir"); </script>
4. 条件语句
if...
if...else...
if...else if...else
switch(n)
case 1:
代码块1
break;
case 2:
代码块2
break;
....
default:
代码块