Blogger Information
Blog 17
fans 1
comment 0
visits 8738
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
认识js的函数,常量,变量以及命名规则
P粉933302309
Original
443 people have browsed it

一,常量和变量

  1. //常量(常量必须初始化/赋值)
  2. let a = "我是常量";
  3. console.log(a);
  4. // 变量
  5. // 声明变量并且初始化(变量可以不初始化,后面在赋值)
  6. let b = "我是变量";
  7. // 二次赋值
  8. console.log(b + "123");

二,作用域类型和查看方式

  1. let c = "全局作用域";
  2. console.log(c);
  3. {
  4. let c = "内部作用域";
  5. console.log(c);
  6. }
  7. ·// 作用域权限由内而外!

三,标识符命名规则

  1. // 3.标识符命名规则
  2. // 1.不能以数字开头,不能有特殊符号($和下划线除外)
  3. function test_$name(x, y) {
  4. return x + y;
  5. }
  6. console.log(test_$name(10, 30));
  7. // 驼峰式命名
  8. // GetName/getName
  9. // 蛇形命名
  10. // Get_Nmae

四,三种函数

  1. // 1.1命名函数
  2. function GetName(x, y) {
  3. return x - y;
  4. }
  5. console.log(GetName(10, 20));
  6. // 1.2匿名函数
  7. let sum = function (x, y) {
  8. return x - y;
  9. };
  10. console.log(GetName(10, 20));
  11. // 1.3箭头函数(去掉function,用旁箭头在大括号左边表示)
  12. let sum1 = (x, y) => {
  13. return x - y;
  14. };
  15. console.log(GetName(10, 20));
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