`

CHAPTER 2 Lexical Structure

 
阅读更多
2.1 Character Set

Javascript采用Unicode编码

2.1.1 Case Sensitivity

Javascript是大小写敏感的语言

2.1.2 Whitespace, Line Breaks, and Format Control Characters

Javascript忽略空格和换行

2.1.3 Unicode Escape Sequences

由于系统和软件的关系,可能无法读取和显示整个unicode字符,为什么支持这项功能,Unicode采用一个特殊的6个字符组成的ASCII编码来表示。如:

"café" === "caf\u00e9" // => true

2.2 Comments

// 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.
*/


2.3 Literals

字面量就是直接可以在程序里面出现的
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


2.4 Identifiers and Reserved Words

标识符和保留关键字,标识符必须以一个字母,下划线,dollar符号开头,后面可以是字母,数字,下划线,dollar符号。

2.4.1 Reserved Words

保留关键字有:
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


2.5 Optional Semicolons

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权威指南(第6版)

    Chapter 2 Lexical Structure Chapter 3 Types, Values, and Variables Chapter 4 Expressions and Operators Chapter 5 Statements Chapter 6 Objects Chapter 7 Arrays Chapter 8 Functions Chapter 9 Classes and...

    JavaScript权威指南(第6版).JavaScript:The.Definitive.Guide

    Chapter 2 Lexical Structure Chapter 3 Types, Values, and Variables Chapter 4 Expressions and Operators Chapter 5 Statements Chapter 6 Objects Chapter 7 Arrays Chapter 8 Functions Chapter 9 Classes and...

    PROFESSIONAL F# 2.0

    - **Lexical Structure (Chapter 2):** This chapter covers the lexical structure of F#, including identifiers, keywords, operators, and comments. It lays the groundwork for understanding how code is ...

    Nature Language Processing with Python

    Chapter 2. Accessing Text Corpora and Lexical Resources Chapter 3. Processing Raw Text Chapter 4. Writing Structured Programs Chapter 5. Categorizing and Tagging Words Chapter 6. Learning to Classify ...

    Object-Oriented Software Construction 2nd

    Chapter 2: Criteria of object orientation 21 2.1 ON THE CRITERIA 21 2.2 METHOD AND LANGUAGE 22 2.3 IMPLEMENTATION AND ENVIRONMENT 31 2.4 LIBRARIES 33 2.5 FOR MORE SNEAK PREVIEW 34 2.6 BIBLIOGRAPHICAL ...

    C++_CLI标准.pdf

    #### Lexical Structure (Chapter 9) - **Tokens**: Section 9.1 covers tokens, which are the basic building blocks of the C++/CLI language. - **Identifiers**: Section 9.1.1 explains identifiers used in ...

    The C programming Language(chm格式完整版)

    Chapter 2: Types, Operators and Expressions Variable Names Data Types and Sizes Constants Declarations Arithmetic Operators Relational and Logical Operators Type Conversions Increment and ...

    HPL: Vol. IV: Functional and Logic Programming Languages

    Chapter 2—Emacs Lisp: A Short Description 2.1. GNU Emacs and Emacs Lisp 2.2. Lisp Lists 2.2.1. Parts of Lisp 2.3. Example: Two Plus Two 2.4. Evaluation 2.5. A Function Definition 2.5.1. An ...

    The C programming Language

    Call by Value Character Arrays External Variables and Scope <br>Chapter 2: Types, Operators and Expressions Variable Names Data Types and Sizes Constants Declarations ...

    英语文体学ChapterSurfaceStructureDeviationPPT课件.pptx

    **词汇上的偏离(Lexical Deviation)**可能涉及到使用习语、俚语、借词、比喻和象征性语言,以增强语言的表达力和深度。 最后,**书写形式上的偏离(Graphological Deviation)**可能包括拼写简化、大写字母的使用...

    Decompiling Android.pdf

    1. **Chapter 3: Inside the DEX File** - This chapter delves into the structure and contents of DEX files, providing insights into how decompilers can extract meaningful information from them. ...

    The Art of Assembly Language Programming

    Pointers to Structures and Arrays of Structure <br> 5.8 Laboratory Exercises 5.9 Programming Projects 5.10 Summary 5.11 Questions <br>Chapter Six - The 80x86 Instruction Set 6.0 ...

Global site tag (gtag.js) - Google Analytics