Blogger Information
Blog 37
fans 0
comment 1
visits 28116
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Js变量、常量、四种函数类型和五种基本数据类型
kong
Original
802 people have browsed it

Js变量、常量、四种函数类型和五种基本数据类型

变量、常量

  1. //声明变量
  2. let userName
  3. //赋值(第一次赋值叫初始化)
  4. userName = '小明';
  5. //更新(第二次叫更新)
  6. userName = 'PHP中文网'
  7. // 声明和初始化合并
  8. let name = '墨子'
  9. // 不能随便更改的使用常量
  10. //常量
  11. const url = 'https://www.baidu.com'
  12. console.log(url)

四种函数类型

  1. //1. 命名函数
  2. function sum1(a,b){
  3. // 将字符串的定界符(双引号或者单引号),换成反引号(``)
  4. return `${a}+${b}=` +(a+b)
  5. }
  6. // 调用
  7. console.log(sum1(10,20))
  8. // 2. 匿名函数
  9. let sum2 = function(a ,b){
  10. return `${a}+${b} = ` + (a+b)
  11. }
  12. console.log(sum2(3 ,4))
  13. // 3. 箭头函数
  14. //当只有一个参数的时候,括号可以不写
  15. //没有参数的时候括号不能省
  16. let sum3 = (a ,b) =>{
  17. return (a+b)
  18. }
  19. console.log(sum3(3 ,4))
  20. // 4. 立即执行函数
  21. //将声明和调用二合一,声明以后直接执行
  22. ;((a,b) => {
  23. console.log(a+b)
  24. })(30 ,50)

数据基本类型

  1. // 1. 数值(不区分整数和小数)number
  2. console.log(100 ,typeof 100)
  3. // 2. 字符串 string
  4. console.log('admin',typeof 'admin')
  5. // 3. 布尔类型 只有两个值false ,true
  6. console.log(false,typeof false)
  7. console.log(true,typeof true)
  8. // 4. null 空对象
  9. console.log(null,typeof null)
  10. // 5. undefined 未定义
  11. console.log(undefined,typeof 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!