Blogger Information
Blog 16
fans 0
comment 0
visits 5687
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
变量,常量,,四种函数类型及基本类型
Sinan学习博客
Original
463 people have browsed it

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

1.1 变量/常量

  1. let uname = 'wsn';//变量
  2. const PI = 3.14;//常量

1.2 四种函数类型

  • 命名函数
  • 匿名函数
  • 箭头函数
  • 立即执行函数
  1. //命名函数
  2. function num(a,b){
  3. return a+b;
  4. }
  5. num(1,2) //3
  6. //匿名函数
  7. let num1 = function(a,b){
  8. return a*b;
  9. }
  10. num1(2,5) //10
  11. //箭头函数
  12. let uname = (name) => {
  13. console.log("姓名: " + name); //姓名: 张三
  14. }
  15. uname("张三")
  16. //箭头函数只有一个参数的简写
  17. let uname = name => console.log("姓名: " + name);
  18. //立即执行函数
  19. //将声明和调用二合一,声明完直接调用。
  20. ;(function num(a,b){
  21. console.log(a+b);
  22. })(1,5)
  23. //简化
  24. ;((a,b) => {
  25. console.log(a+b);
  26. })(1,6)
  27. //再简化
  28. ;((a,b) => console.log(a+b))(1,6)

2. 实例演示五种基本数据类型

  1. let num = 123;
  2. console.log(num , typeof num) // 123 number 数组类型
  3. let uname = "张三";
  4. console.log(uname, typeof uname) // 张三 string 字符串类型
  5. let bool = true;
  6. console.log(bool, typeof bool) // true boolean 布尔类型
  7. let a = null;
  8. console.log(a, typeof a) // null object null是对象类型
  9. let b;
  10. console.log(b,typeof b) // undefined undefined 未定义
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