|-运算符
|--基础运算符 + - * / %
|----加号:数字的求和、字符串的拼接
|----减号:数字的减法、对数字取反
|----乘法、除法、取余
var a = 10;
var b = 10;
var c = a + b;
var d = "hello ";
var e = "world";
alert(c);
alert(a + d);
alert(d + e);
|--复合运算 += -= *= /= %=
var f = "10";
f = f + 2;
f += 2;
alert(f);
|-自增自减 ++ --
|--注意位置a = b++;(先赋值再自加) a = ++b;(先自加再赋值)
var g = 5;
g++;
g = g + 1;
g += 1;
alert(g);
var h = g++;
h = g;(先执行)
g++;(再执行)
alert(h);
var k = ++g;
g++;(先执行)
k = g;(再执行)
alert(k);
|--关系运算符 > < >= <= !=(不等于) == (只判断数字,字符串类型的数字会当作数字型来判断) ===(会判断字符的类型)
var l = 3 >= 2;
var p = 123;
var q = "123";
alert(l);
alert(p != q);
alert(p !== q );
alert(p == q);
alert(p === q );
|--逻辑运算符
|----逻辑非 ! (not)
var aa = 2;
var bb = 3;
var cc = !(aa >= bb);
alert(cc);
|----逻辑与 && (and)
var dd = 2 >= 3; /*flase*/
var ee = 4 >= 1; /*/true*/
alert(dd && ee);
|----逻辑或 || (or)
var dd = 2 >= 3; /*flase*/
var ee = 4 >= 1; /*/true*/
alert(dd || ee);
|--三元运算符 条件?值1(true):值2(false)
var bl = 2>=1?"对":"错";
alert(bl);
var spmc = prompt("请输入商品名称");
var spmc = spmc == "鸡块"?"请给我10元":spmc == "汉堡"?"请给我15元":spmc == "可乐"?"请给我5元":"请输入正确的商品";
alert(spmc);