Blogger Information
Blog 17
fans 0
comment 0
visits 6097
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常量、变量函数及数据类型
生活需要加油
Original
286 people have browsed it

常量、变量函数及数据类型

1. 实例演示变量,常量,与常用的四种函数类型

  1. // ! 1. 数据
  2. //1. 变量
  3. let uName = "dhw"
  4. console.log(uName)
  5. uName = "dxy"
  6. console.log(uName)
  7. //2. 常量
  8. const a = 100
  9. console.log(a)
  10. console.log("---------------")
  11. // ! 2. 函数
  12. //1. 命名函数
  13. function sum(a, b) {
  14. return `${a} + ${b} = ` + (a + b)
  15. }
  16. console.log(sum(10, 20))
  17. // 2. 匿名函数: 函数变量化
  18. let sum2 = function (a, b) {
  19. return `${a} + ${b} = ` + (a + b)
  20. }
  21. console.log(sum2(20, 30))
  22. // 3. 箭头函数: 匿名函数的简化
  23. let sum3 = (a, b = 20) => {
  24. return `${a} + ${b} = ` + (a + b)
  25. }
  26. console.log(sum3(20, 50))
  27. console.log(sum3(20))
  28. // 参数不足时可用默认值代替
  29. // return只有一行代码,可以在简化
  30. let sum4 = (a, b = 20) => `${a} + ${b} = ` + (a + b)
  31. console.log(sum4(25, 55))
  32. let double = a => `${a} * 2 = ` + a * 2
  33. console.log(double(25))
  34. // 4. 立即执行函数: IIFE
  35. ;(a => console.log(`${a} * 2 = ` + a * 2))(30)
  36. ```运行结果:
  37. ![](https://img.php.cn/upload/image/358/378/821/1676450663988995.png)
  38. ##2. 实例演示五种基本数据类型
  39. ```js
  40. // 1. 数值,number
  41. console.log(200, typeof 200)
  42. // 2. 字符串, string
  43. console.log("dhw", typeof "dhw")
  44. let x = 10,
  45. y = 20
  46. console.log(`${x} + ${y} = `, x + y)
  47. // 3. 布尔类型, boolean
  48. console.log(true, typeof true)
  49. // 4. null,空对象
  50. console.log(null, typeof null)
  51. // 5. undefined, 未定义
  52. let addr
  53. console.log(addr)

运行结果:

3. 预习三种引用类型

数组 对象 和 函数

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!