Blogger Information
Blog 7
fans 0
comment 1
visits 1841
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 实例演示四种常用的函数类型 2. 实际演示原始数据类型与引用类型
PHP中文网用户-6406556
Original
272 people have browsed it
  1. // 1.四种常见函数类型
  2. //1.命名函数
  3. function QQQ(a, b) {
  4. return `${a}+${b}=` + (a + b); //模版字面量,支持表达式
  5. }
  6. console.log(QQQ(1, 2));
  7. //2.匿名函数
  8. const ssj = function (a, b) {
  9. return `${a}+${b}=` + (a + b);
  10. };
  11. console.log(ssj(2, 2));
  12. //3.立即执行函数IIFE
  13. let resull = (function (a, b) {
  14. return `${a}+${b}=` + (a + b);
  15. })(3, 5);
  16. console.log(resull);
  17. //4.箭头函数(箭头函数没有自己的this)
  18. //单参数可省()
  19. let a123 = a => a + a; //只有一个返回值时可省{}
  20. console.log(a123(22));
  21. //无参或多参
  22. let a1234 = () => 5 * 5;
  23. console.log(a1234());
  24. // 2.原始数据类型:
  25. `string`, `number`, `boolean`, `null`, `undefined`;
  26. // 引用数据类型:
  27. `array`, `object`, `function`;
  28. const arr = [10, "admin", true]; //数组
  29. console.log(arr[2]);
  30. let user = { id: 100, uname: "admin" }; //对象
  31. console.log(user.uname); //如果属性都是合法标识符,可用‘.’来访问成员,不是的只能用[]
  32. //函数是对象,所以可以添加属性

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!