Blogger Information
Blog 11
fans 0
comment 0
visits 3159
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 实例演示分支与循环结构; 2. 实例演示对象字面量的简化; 3. 实际演示解构赋值与应用场景(克隆与传参)
至亲难忘
Original
209 people have browsed it
  1. 分支

  • 单分支
    1. let ps1 = true;
    2. if(ps1){
    3. console.log('这是个单分支');
    4. }
    单分支
  • 双分支
    1. let ps2 = false;
    2. if(ps2 === true){
    3. console.log('这是正确的')
    4. }else{
    5. console.log('这是双分支')
    6. }
    双分支
  • 多分支
    1. let age =12
    2. if(age>=18 && age<=35){
    3. console.log('你是个青年人,努力挣钱')
    4. }if(age>35 && age<=80){
    5. console.log('您是老年人,请注意身体')
    6. }else{
    7. console.log('你是未成年,好好学习')
    8. }
    多分支
  • 多分支语法糖
    1. let age1=45
    2. switch (true) {
    3. case age1 >=18 && age1 <= 35:
    4. console.log('你是个青年人,努力挣钱')
    5. break
    6. case age1 <=80:
    7. console.log('您是老年人,请注意身体')
    8. break
    9. default:
    10. console.log('你是未成年,好好学习')
    11. }
    多分支语法糖

2.对象字面量简化


1.for-in

  1. let user= {id:1,username:'张三',class:'三年级'}
  2. for(let key in user){
  3. console.log(user[key])
  4. }

for-in
2.forEach

  1. let user= ['张三','李四','王二麻子']
  2. user.forEach(item => {
  3. console.log(item)
  4. });

forEach
3.for-of

  1. let user= ['王五','赵六','三儿']
  2. for(let value of user){
  3. console.log(value)
  4. }

for-of
4.for

  1. let user= ['红','黄','蓝','lv']
  2. for(let i=0 ;i<user.length;i++){
  3. console.log(user[i])
  4. }

for


克隆

  1. let item ={name:'张三',age:30,sex:'男'}
  2. let { ...obj } =item
  3. console.log(obj)
  4. console.log(item)
  5. console.log(item === obj)//不全等,表示不是同一个内容

克隆


传参

  1. let item = {name:'张三',age:30,sex:'男'}
  2. let show = function(item){
  3. return `${item.name}:${item.age}:${item.sex}`
  4. }
  5. console.log(show({name:'法外狂徒',age:45, sex:'女'}))

传参

对象结构传参
  1. show = ({name,age,sex})=>`${name}:${age}:${sex}`
  2. console.log(show({name:'王五',age:54,sex:'人妖'}))

对象结构传参

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