Blogger Information
Blog 19
fans 0
comment 0
visits 10754
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
不同的数组类型与访问方式与分支的不同类型
牙森江
Original
494 people have browsed it

1.不同的数组类型

1.1 原始
原始数据类型有5个:数值,字符串,布尔值,undefined,null 。

  1. //数值
  2. let a = 1
  3. console.log(a)
  4. //字符串
  5. let b = 'abc'
  6. console.log(b)
  7. //布尔值
  8. console.log(true)
  9. // undefined
  10. let a
  11. console.log(a)
  12. // null
  13. console.log(null)
  14. //查询方式用 typeof
  15. //比如:
  16. let b = 'abc'
  17. console.log(b, typeof b)
  18. //运行结果
  19. abc string

1.2 数据类型:引用
常用的引用有数组,对象,函数

  1. // 1.数组
  2. let a = ['phone', 300 , true]
  3. console.log(a[0],a[1],a[2])
  4. //2.对象
  5. name: 'phone',
  6. price: 300,
  7. 'in stock': true,
  8. }
  9. console.log('object: ', item['name'], item['price'], item['in stock'])
  10. // 3.函数
  11. //函数格式一下!
  12. function fn1() {}
  13. //用一个变量来引用的函数
  14. const fn2 = function () {}
  15. // 箭头函数
  16. const fn3 = () => {}

2.分支的不同类型

分支有单分支、双分支、多少分支
1.单分支

  1. if (true) {
  2. console.log('成功')
  3. }

2.双分支

  1. if (!true) {
  2. console.log('成功')
  3. } else {
  4. console.log('失败')
  5. }
  6. //代码运行效果
  7. 失败

3.多分枝

  1. grade = 'A'
  2. if (grade === 'A') {
  3. console.log('优秀')
  4. } else if (grade === 'B') {
  5. console.log('良好')
  6. } else if (grade === 'C') {
  7. console.log('合格')
  8. } else if (grade === 'D') {
  9. console.log('补考')
  10. } else {
  11. console.log('非法输入')
  12. }
  13. //代码运行效果
  14. 优秀
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