Blogger Information
Blog 42
fans 0
comment 0
visits 15644
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0720数据类型分支与循环类型
小言
Original
316 people have browsed it

数据类型

分为原始类型和引用类型

原始类型

  1. console.log(typeof 100);
  2. console.log(typeof 'aaaa');
  3. console.log(typeof true, typeof false);
  4. let a; //undefined 是变量的默认值
  5. console.log(a);
  6. console.log(typeof null);

引用类型

主要包括了,数组、对象类型、函数
  1. const arr =['电脑', 2, 5000];
  2. console.table(arr);
  3. console.log(arr[0]);
  4. console.log(arr[1]);
  5. console.log(arr[2]);
  6. console.log(arr,length);
  7. console.log(typeof arr);
  8. console.log(Array.isArray(arr));

  1. let obj ={
  2. name: '电脑',
  3. num:2,
  4. price:5000,
  5. 'my email': '123@qq.com',
  6. };
  7. console.log(obj['name']);
  8. console.log(obj.name);
  9. console.log(obj['my email']);

函数,函数既是数据类型,也是对象。
最在的优点就是可以当成函数的参数进行回调。

分支

分支 就是有条件的执行某段代码

分类:单分支、双分支或者多分支

  1. age = 121;
  2. if(age >= 18 && age <35){
  3. console.log('允许观看');
  4. }
  5. //这一块就是单分支
  6. else if(age >= 35 && age < 60){
  7. console.log('允许多人观看');
  8. }
  9. //双分支
  10. else if(age >= 60 && age < 120){
  11. console.log('建议陪同观看');
  12. }
  13. //多分支
  14. else if(age >= 120 || age < 8){
  15. console.log('非法年龄');
  16. }
  17. //默认
  18. else {
  19. console.log('少儿不易');
  20. }

循环

1.索引初始化: 0

2.循环条件: i < length

3.更新循环条件: i++

  1. const colors = ['red', 'green', 'blue'];
  2. let i = 0;
  3. let length = colors.length;
  4. if(i < length){
  5. console.log(colors[i]);
  6. //i = i + 1;
  7. i++;
  8. }
  9. if(i < length){
  10. console.log(colors[i]);
  11. i = i + 1;
  12. }
  13. if(i < length){
  14. console.log(colors[i]);
  15. i = i + 1;
  16. }else {
  17. console.log('遍历结束');
  18. }

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!