Blogger Information
Blog 15
fans 1
comment 1
visits 174141
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常用函数类型和常用数据类型
想做肥仔
Original
1127 people have browsed it

1.函数类型

  1. // 常用函数类型
  2. // 1命名函数
  3. function Num(a,b){
  4. return a + b ;
  5. };
  6. console.log(Num(3,7));
  7. // 2匿名函数
  8. // 赋值调用
  9. let a = function (str){
  10. return'Hello' + str;
  11. };
  12. console.log(a('-Word'));
  13. // 立即调用IIFE
  14. console.log(
  15. (function (str){
  16. return'这是一个匿名函数' + str;
  17. })('使用的是立即调用方法')
  18. );
  19. // 3箭头函数
  20. b = (c,f) =>{
  21. console.log(3+2);
  22. }
  23. b();
  24. let x = cf =>'Are-you' + cf;
  25. console.log(x('-OK?'));

2数据类型

  1. // 2常用数据类型
  2. // 2-1数字类型 number
  3. console.log(typeof 999,typeof 666);
  4. //2-2字符串类型 string
  5. console.log(typeof'Orange');
  6. // 2-3 布尔类型 boolean
  7. console.log(typeof true,typeof false);
  8. // 2-4 未定义 undefined
  9. console.log(typeof undefined);
  10. //2-5空值 null
  11. console.log(null);
  12. // 2-6 数组 Array
  13. const arr = [996,007,955];
  14. console.log(arr);
  15. //返回 ture 就验证这是一个数组
  16. console.log(Array.isArray(arr));
  17. // 2-6 对象 object
  18. let obj = {
  19. id: 1,
  20. userName: '马化腾',
  21. arr: [1,2,3],
  22. 'myQQ': '1684302917',
  23. };
  24. console.log(obj);
  25. console.log(arr);
  26. console.log(obj['myQQ']);
  27. // 2-6 函数 function
  28. // 当值,闭包
  29. function a1() {
  30. let b1 =2;
  31. return function() {
  32. return b1++;
  33. };
  34. }
  35. console.log(a1());
  36. const g = a1();
  37. console.log(g());
  38. console.log(g());
  39. console.log(g());
  40. // 当对象,添加属性和方法
  41. // 属性
  42. let a2 = function(){};
  43. a2.myName = '马化腾';
  44. console.log(a2.myName);
  45. // 方法
  46. a2.youName = function(){
  47. console.log(this.myName);
  48. };
  49. a2.youName();

展示

展示

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