1 算式运算符
<!-- 第一部分 算式运算符 --> <h1>算式运算符 </h1> <script> console.log("算式运算符") // 算数运算符一 console.log(2 + 2); console.log(2 / 2); console.log(2 * 2); console.log(2 - 2); console.log(8 % 2); //算数运算符二 var num1 = 2000 var num2 = 100 document.write("<h1>" + num1 + num2 + "</h1>") document.write(num1 - num2) document.write("<h1>" + num1 * num2 + "</h1>") document.write("<h1>" + num1 / num2 + "</h1>") document.write("<h1>" + num1 % num2 + "</h1>") document.write("<h1>" + num1++ + "</h1>") document.write("<h1>" + ++num1 + "</h1>") document.write("<h1>" + num2-- + "</h1>") </script>
2 比较运算符
<!-- 第三部分 比较运算符 Boolean类型 --> <script> console.log("比较运算符 Boolean类型") var aa = 12; var bb = 4; console.log(aa == bb) console.log(aa > bb) console.log(aa < bb) console.log(aa >= bb) console.log(aa <= bb) console.log(aa != bb) console.log(aa!==bb) </script>
3 逻辑运算符
<!-- 逻辑运算符 --> <script> //逻辑运算符 boolean 与或非 console.log(3 > 5 && 3 > 2); console.log(32 > 53 && 32 < 2); console.log(3 > 5 || 3 > 2); console.log(true); //逻辑短路 console.log(123 && 4567); console.log(0 && 4567); console.log(0 && 1 + 2 && 456 * 89889); //逻辑或短路 console.log(123 || 456); var aa = 123; var bb = 234; var cc = 123; console.log(aa = cc) console.log(aa == cc) console.log(aa == cc) console.log("等于号的区别") alert("逻辑运算符||") console.log(!true); console.log(!false); </script>
4 赋值运算符
<!--第二部分 赋值运算符 --> <script> console.log("赋值运算符") var a = 20; var b = 5; console.log("+等于" + (a += b)); console.log("-等于" + (a -= b)); console.log("*等于" + (a *= b)); console.log("%等于" + (a %= b)); console.log("/等于" + (a /= b)); </script>
5 三元运算符