zoukankan      html  css  js  c++  java
  • JavaScript 命名规则

    来源 :http://www.codelifter.com/main/tips/tip_020.shtml 

    The following are the rules for naming JavaScript variables:

    1.
    A variable name cannot start with a numeral. For instance,
    3x or 2goats or 76trombones would all be illegal variable names.

    You can, however, have numbers within a JavaScript variable name; for instance
    up2me or go4it would both be perfectly valid variable names.

    不能以数字开头


    2.
    You cannot have a mathematical or logical operator in a variable name. For instance,
    2*something or this+that would both be illegal... because the * and the + are arithmetic operators. The same holds true for ^, /, \, !, etc.

    变量名中不能含有操作符



    3.
    You must not use any punctuation marks of any kind in a JavaScript variable name, other than the underscore; for example...
    some:thing or big# or do'to would all be illegal.

    The underscore is the exception, and it can be used at the beginning, within, or at the end of JavaScript variable names. You can use names like
    _pounds or some_thing or gallons_ as variable names and they are perfectly legal.

    变量名中不能有标点符号,除了_下划线以外的任何标点符号。

    4.
    JavaScript names must not contain spaces. Ever.

    变量名中不能有空格

    5.
    You cannot use JavaScript keywords (parts of the language, itself) for variable names. Thus
    window or open or location or string would be illegal.  Check a JavaScript reference if in doubt as to whether something is or is not part of the language -- JavaScript has grown into a fairly fully-fleshed language, so you may get some occasional surprises.

    You can, of course, use what are otherwise keywords as parts of variable names. For instance,
    thatWindow or someString or theLocation would all be perfectly acceptable.

    变量中不能用JavaScript语言的关键词。如 window,string,blooean等等

    6.
    JavaScript variable names are case-sensitive. Programmers in other languages are often tripped up by this one, as some languages are not sensitive to case in variable names.


    For instance, all of the following names would be considered completely different variable names in JavaScript: 
    gasbag  Gasbag  GasBag  gasBag

    变量名区分大小写.         

    总结:

    通常情况下变量名只能由大小写的英文字母和数字组成, 即A-Z a-z  0-9构成

    只能以字母或者下划线开头。

    不能包含特殊字符,不能用关键词作变量名。 

    -----------欢迎补充

  • 相关阅读:
    web中状态码及请求方式
    访问服务器时一直在转圈,等待localhost响应
    Address already in use: JVM_Bind 端口被占用的几个解决办法
    Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean)
    taotao商城
    Dubbo的学习
    taotao商城
    sql中有一些保留字,当你的字段名是它的保留字时,这个时候sql语句的字段不加``就会报错
    ssm学习的第一个demo---crm(4)
    ssm学习的第一个demo---crm(3)
  • 原文地址:https://www.cnblogs.com/beenupper/p/5176256.html
Copyright © 2011-2022 走看看