5_运算.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // var a = 1;
  12. // var b = 2;
  13. // console.log(a+b) // 3
  14. // console.log(a-b) //-1
  15. // console.log(a*b-c)//not defined
  16. // console.log(c)// not defined
  17. // var c;//undefined
  18. // console.log(a*b-c) //NaN 运算不下去
  19. // var d = a*7 + b;
  20. // console.log(d)//9
  21. // var a = 1;//number
  22. // var b = '456';//string
  23. // console.log(a+b)// 加法 当两种变量数据类型不统一的时候 一个为number 一个为string 默认进行拼接
  24. // var c = '哈哈哈哈哈'
  25. // console.log(b+c)//string 类型相加 默认进行拼接
  26. // var a = 1;
  27. // var b = true;
  28. // console.log(a+b)// number + boolean boolean转化为number 类型 true = 1 fasle = 0
  29. // var c = 'xxx'
  30. // console.log(c+b)//string + boolean 进行拼接
  31. // var a = 666;
  32. // var b = '123';
  33. // console.log(a-b)//string 参加减法运算 会把里面的内容转化为number类型 进行运算
  34. // var c = 'hahahha777'
  35. // console.log(a-c)//NaN 如果碰到非全数字的string 无法转化 无法参与计算
  36. // var d = false;
  37. // console.log(a-d)//boolean类型 参与减法运算 转化为number true = 1 false = 0
  38. // var a = 666;
  39. // ++a;
  40. // console.log(a)//667
  41. // a++;
  42. // console.log(a)//668
  43. // --a;
  44. // console.log(a)//667
  45. // var c = 777
  46. // // console.log(c++)//先输出 后++ 输出之后 c = 778
  47. // // console.log(++c)//先++ 后输出 c = 779
  48. // c++;// 输出 然后++ c = 778
  49. // console.log(c)
  50. </script>
  51. </body>
  52. </html>