Blogger Information
Blog 20
fans 0
comment 0
visits 8460
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1102作业(实例演示JS中变量常量与函数的声明与使用过程)
A 管志岗-电商策划
Original
326 people have browsed it

1102作业

作业内容:

1. 实例演示不同的数组类型与访问方式

2. 实例演示分支的不同类型,注意else的本质

一、 实例演示JS中变量常量与函数的声明与使用过程

  1. // 变量:
  2. // 1. let 是新推出的变量名称,之前有var,以后不推荐使用
  3. // 比如: let username = '我爱你中国'
  4. 2. const 常量
  5. // 一般用作于名命,用大蛇名命表达
  6. const USER_NAME = '中国人'
  7. // 调取过来就是,数据禁止更新,以后推荐使用这个变量
  8. console.log('USER_NAME=', USER_NAME)
  9. // 声明
  10. function sum(a, b){
  11. runturn 'a + b =' + (a + b)
  12. }
  13. function sum7(a, b) {
  14. return "a + b =", a + b;
  15. }
  16. // 可以简写:
  17. sum7 = (a, b) => {return a + b}
  18. console.log(sum7(1, 2))
  19. // 必须遵循先声明后使用原则,为了以后开发方便
  20. // 这是先声明,变量不在 funtion 的后面,
  21. // 这里的const 也可以用let, 但是为了禁止更新,推荐用const

2. 实例演示分支的不同类型,注意else的本质

函数微分四种:

  1. 名命函数:
    funtion sum(a, b){
    return ‘a + b = ‘,(a + b)
    }
    console.log (sum(1, 3))

  2. 匿名函数
    const sum1 = funtion(a, b){return ‘a + b’, (a + b)}
    // 简写 用的是箭头函数
    const sum1 = (a, b) => {return ‘a + b’, (a + b)}
    console.log(1, 2)

  3. 箭头函数
    const sum1 = (a, b) => {return ‘a + b’, (a + b)}

  4. 立即执行函数
    // funtion 内部加上(),就成了一个表达式,后面再来一个括号(),里面可以传参数了,直接调用。
    let res = (function sum7(a, b) {
    return “a + b =”, a + b;
    })(20, 30);
    console.log(res);

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!