Blogger Information
Blog 8
fans 0
comment 0
visits 2496
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 实例演示变量,常量,与常用的四种函数类型 2. 实例演示五种基本数据类型 3. 预习三种引用类型
alexcy的学习博客
Original
363 people have browsed it

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

  1. // 声明并初始化变量 ,用let(首选)
  2. let username = 'admin'
  3. console.log(username);
  4. // 声明常量,必须初始化,用const
  5. const sex = "男"
  6. console.log(sex);
  7. // 函数
  8. // 1.命名函数,先声明后调用,变量会自动提升
  9. function sum(a,b) {
  10. // return返回值
  11. return 'a+b =' +(a+b)
  12. }
  13. console.log(sum(1,2));
  14. // 2.匿名函数,函数变量化,不能够被自动提升
  15. let sum1 = function (a,b) {
  16. return `${a}*${b}=` +(a*b)
  17. }
  18. console.log(sum1(2,3));
  19. // 3.箭头函数
  20. let sum2 =(a,b=0)=>{
  21. return `${a}+${b} = ` +(a+b)
  22. }
  23. console.log(sum2(7,8));
  24. // 4.立即执行函数
  25. (function (a,b) {
  26. console.log(`${a}+${b} = ` + (a+b));
  27. })(60,50)

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

  1. // 基本数据类型
  2. // 1.数值(不区分整数和小数),number
  3. console.log(200,typeof 200);
  4. // 2.字符串 String
  5. console.log('你好',typeof "你好");
  6. // 3.布尔 true false bool
  7. console.log(true,typeof true);
  8. // 4.null,空对象
  9. console.log(null,typeof null);
  10. // 5.undefined,未定义
  11. let email
  12. console.log(email);

3. 预习三种引用类型

  1. // 1.数组Array,定义要用[]
  2. let name1 = ['aaa','bbb','ccc']
  3. console.log(name1);
  4. // 2.对象Object,定义需要用{}
  5. let name2 = {
  6. title1:"张三",
  7. title2:"李四",
  8. title3:"王五",
  9. }
  10. console.log(name2);
  11. // 3.Function类型,函数不会自动执行,需要通过调用才能运行
  12. function sayHello(data) {
  13. return `hello ${data}`
  14. }
  15. console.log(sayHello('world'));
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