[color=blue]2.1 Character Set[/color]
Javascript采用Unicode编码
[color=blue]2.1.1 Case Sensitivity[/color]
Javascript是大小写敏感的语言
[color=blue]2.1.2 Whitespace, Line Breaks, and Format Control Characters[/color]
Javascript忽略空格和换行
[color=blue]2.1.3 Unicode Escape Sequences[/color]
由于系统和软件的关系,可能无法读取和显示整个unicode字符,为什么支持这项功能,Unicode采用一个特殊的6个字符组成的ASCII编码来表示。如:
"café" === "caf\u00e9" // => true
[color=blue]2.2 Comments[/color]
[color=blue]2.3 Literals[/color]
字面量就是直接可以在程序里面出现的
[color=blue]2.4 Identifiers and Reserved Words[/color]
标识符和保留关键字,标识符必须以一个字母,下划线,dollar符号开头,后面可以是字母,数字,下划线,dollar符号。
[color=blue]2.4.1 Reserved Words[/color]
保留关键字有:
[color=blue]2.5 Optional Semicolons[/color]
Note that JavaScript does not treat every line break as a semicolon: it usually treats line breaks as semicolons only if it can’t parse the code without the semicolons.
Javascript将结尾看成是一个分号:只有在结尾无法形成语句的时候,才会将结尾看成是一个分号,就是后面的代码如果加进来,就会出错,那么结尾就是一个分号,不再加入后面那行代码了,有点象贪婪原则。例子:
var y = x + f
(a+b).toString()
实际的结果就是:
var y = x + f(a+b).toString();
如果第一个语句是以return break continue结尾,那么分号会自动加上,不会加入下面的句子,例如:
return
true;
JavaScript assumes you meant:
return; true;
However, you probably meant:
return true;
另一个特殊情况就是++ --的使用,它们即可以是前缀的也可以是后缀的,那么如果你想要让它们变成是后缀的,那么它们必须在一行里。例如:
x
++
y
It is parsed as x; ++y;, not as x++; y.
Javascript采用Unicode编码
[color=blue]2.1.1 Case Sensitivity[/color]
Javascript是大小写敏感的语言
[color=blue]2.1.2 Whitespace, Line Breaks, and Format Control Characters[/color]
Javascript忽略空格和换行
[color=blue]2.1.3 Unicode Escape Sequences[/color]
由于系统和软件的关系,可能无法读取和显示整个unicode字符,为什么支持这项功能,Unicode采用一个特殊的6个字符组成的ASCII编码来表示。如:
"café" === "caf\u00e9" // => true
[color=blue]2.2 Comments[/color]
// This is a single-line comment.
/* This is also a comment */ // and here is another comment.
/*
* This is yet another comment.
* It has multiple lines.
*/
[color=blue]2.3 Literals[/color]
字面量就是直接可以在程序里面出现的
12 // The number twelve
1.2 // The number one point two
"hello world" // A string of text
'Hi' // Another string
true // A Boolean value
false // The other Boolean value
/javascript/gi // A "regular expression" literal (for pattern matching)
null // Absence of an object
[color=blue]2.4 Identifiers and Reserved Words[/color]
标识符和保留关键字,标识符必须以一个字母,下划线,dollar符号开头,后面可以是字母,数字,下划线,dollar符号。
[color=blue]2.4.1 Reserved Words[/color]
保留关键字有:
break delete function return typeof
case do if switch var
catch else in this void
continue false instanceof throw while
debugger finally new true with
default for null try
[color=blue]2.5 Optional Semicolons[/color]
Note that JavaScript does not treat every line break as a semicolon: it usually treats line breaks as semicolons only if it can’t parse the code without the semicolons.
Javascript将结尾看成是一个分号:只有在结尾无法形成语句的时候,才会将结尾看成是一个分号,就是后面的代码如果加进来,就会出错,那么结尾就是一个分号,不再加入后面那行代码了,有点象贪婪原则。例子:
var y = x + f
(a+b).toString()
实际的结果就是:
var y = x + f(a+b).toString();
如果第一个语句是以return break continue结尾,那么分号会自动加上,不会加入下面的句子,例如:
return
true;
JavaScript assumes you meant:
return; true;
However, you probably meant:
return true;
另一个特殊情况就是++ --的使用,它们即可以是前缀的也可以是后缀的,那么如果你想要让它们变成是后缀的,那么它们必须在一行里。例如:
x
++
y
It is parsed as x; ++y;, not as x++; y.