javascript运算操作符一般有 + - * / % = ()
+
1.数学运算、字符串拼接
2.任何数据类型加字符串都等于字符串
var a = 1 + 1; // 2 (Number) var b = 1 + '1'; //11 (String)
- * / % = ()
优先级=最弱, ()优先级较高
var num = 1 / 0; // Infinity var num = -1 / 0; // -Infinity var num = 0 / 0; // NaN
++ -- += -= /= *= %=
var a = 1; console.log(a++); //1 console.log(a); //2 console.log(++a); //3 console.log(a); //3 var b = 1; b += 2; console.log(b) //3
< >
// 字符比较式通过ascall码比较 console.log('a' < 'b') //true console.log('A' < 'a') //true console.log(NaN == NaN) //false console.log(null == null) //true console.log(undefined == undefined) //true
逻辑运算符 && || !
var a = 1 && 2; console.log(a); //2 会返回原来的值 var a = 2 || 3; console.log(a); //2 会返回原来的值 var a = !2; console.log(a); //false 会转成Boolean值 var a = !!2; console.log(a); //true 会返回Boolean值
//其中 undefined null NaN "" 0 false -> 转Boolean值为false
条件语句
if , else if , else
循环语句
for , while , do while
switch case
var a = 1 if(a > 10) { console.log('执行1') }else if(a > 5 && a < 10) { console.log('执行2') }else { console.log('执行3') }
比较简单,就水了一篇O(∩_∩)O哈哈~
end !!!