5_数值型.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var a = 1;
  11. var b = 2;
  12. // 加法
  13. console.log(a+b);
  14. // 由于计算机计算精度问题 0.1 + 0.2 不等于0.3
  15. console.log(0.1+0.2);
  16. // 减法
  17. console.log(2-1);
  18. // 乘法
  19. console.log(2*2);
  20. // 除法
  21. console.log(4/2);
  22. // 取余
  23. console.log(5%2);
  24. // 括号
  25. console.log((2+1)*2);
  26. // NaN not a number 当我们看到这个类型表示数学运算中出现了非数值类型 (加法除外)
  27. // 除了加法其他的数学运算只要有一个操作数不是数值型那么就返回一个NaN
  28. console.log("a" * 2);
  29. // 如果参与数学运算的操作数中有一个是字符串 如果这个字符串是一个数字那么可以把它转换成数值型运算
  30. console.log("6" * 2);
  31. </script>
  32. </body>
  33. </html>