4_运算.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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*4+b-c) //NaN
  14. // console.log(c)// undefined
  15. // var c = a + b; //变量是可以参与运算的
  16. // alert(c)
  17. // var d = a * 2 + b ;
  18. // alert(d)
  19. // var a = 1; //number
  20. // var b = '456' // string
  21. // console.log(a+b) // 加法 当两种变量数据类型不统一 一个为number 一个为string 默认进行拼接
  22. // var c = '哈哈哈哈'
  23. // console.log(b+c)//string类型相加 默认拼接
  24. // var d = true
  25. // console.log(a+d) //2 number + boolean boolean 转为 number类型 当为true 值为1 false 值为0
  26. // console.log(c+d) //哈哈哈哈true
  27. // var h;
  28. // console.log(h+c)//碰到string 相加 都进行拼接
  29. // var a = 123;
  30. // var b = '456';
  31. // console.log(b-a)//string 参与减法运算 会把里面的内容转为number类型
  32. // var c = 'haha777'
  33. // console.log(c-a)//NaN 但是如果碰到非全数字的string 无法转化 那么无法参与计算
  34. // var d = false
  35. // console.log(a-d)//boolean类型 参与加法运算 转为number true为1 false为0
  36. // var a = 111;
  37. // a++;
  38. // console.log(a) //a++ 自增 每次+1
  39. // //a 112
  40. // a--;
  41. // console.log(a)
  42. // var a = 666;
  43. // ++a;
  44. // console.log(a)//667
  45. // a++;
  46. // console.log(a)/668
  47. // --a;
  48. // console.log(a)//667
  49. // console.log(a)
  50. // var c = a++;//先输出 后++
  51. // console.log(c)//667
  52. // console.log(++c)//668
  53. // console.log(a)//668
  54. var a = 5
  55. console.log(a++)//5 先输出 后++ a=6
  56. console.log(++a)//先++ 后输出 a=7
  57. </script>
  58. </body>
  59. </html>