Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript中的标点符号(逗号、分号) #92

Open
Qingquan-Li opened this issue Apr 22, 2018 · 0 comments
Open

JavaScript中的标点符号(逗号、分号) #92

Qingquan-Li opened this issue Apr 22, 2018 · 0 comments

Comments

@Qingquan-Li
Copy link
Owner

Qingquan-Li commented Apr 22, 2018

  1. 语句结尾的分号 ; 表示语句的结束,是可以省略的,但是建议都写上

    • 声明变量:

      var pi = 3.14;
      var __timer = setInterval("timer()", 1000);
    • 匿名函数(存储在变量中的函数不需要函数名称。它们总是使用变量名称调用):

      // The function ends with a semicolon because it is a part of an executable statement.
      var x = function (a, b) {
           return a * b;
      };
      var z = x(4, 3);
    • (BOM) window 对象的 setInterval() 方法中使用匿名函数:

      setInterval(function() {
          alert("Hello");
      }, 3000);

  2. 逗号 , 用于内容分隔

    • 声明多个变量:

      var name="Fatli", age=22, job="programmer";
    • 数组中的多个值

      var cars = ["Tesla", "BMW", "Lamborghini"];
    • 分隔对象属性(键值对):

      var person = {firstName:"Ben", lastName:"Fatli", age:22, eyeColor:"black"};

  3. 函数 {} 后的分号建议省略,因为 } 就代表一条完整语句的结束

    function name(parameter1, parameter2, parameter3) {
        code to be executed
    }




—— 拓展:Javascript编程风格

@Qingquan-Li Qingquan-Li changed the title JavaScript 中的标点符号(逗号、分号) JavaScript中的标点符号(逗号、分号) Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant