used to:
(so that they react to a viewer’s actions)
and
(visual or otherwise, as HTML is static)
NO!
even if the name is misleading,
except
for a superficial syntactic resemblance,
JavaScript is completely different
from the Java programming language
has
outgrown its scripting-language roots
to become
a robust and efficient general-purpose language.
is well-suited to
object-oriented
and
functional programming
styles.
high-level
dynamic
untyped
interpreted
programming language.
widespread - all modern web browsers include JS interpreters
popular - majority of modern web sites use it
Lexical Structure
Types, Values and Variables
Expressions and Operators
Statements
Objects
Arrays
Functions
Classes and Modules
Pattern Matching with Regular Expressions
1. Character Set
2. Case Sensitivity
3. Whitespace
4. Comments
5. Literals
6. Identifiers
7. Reserved Words
8. Optional Semicolons
The lexical structure of a programming language is
the set of elementary rules
that specifies how you write programs in that language.
1. Character set:
Unicode
a character coding system
designed to support the worldwide interchange, processing, and
display
of written texts of the diverse languages and technical disciplines. It also supports classical and historical texts of many written languages.
internally source code is treated as a sequence of UTF 16 code units
externally, when a web browser loads a source file via a script tag, it determines the encoding
to support older technology that can not display or input the full set of Unicode characters,
unicode escapes have been defined: \u followed by four hexadecimal digits
2. Case
sensitivity:
capitalization of letters matters
3. White space:
spaces and line breaks are for most part ignored,
programs can be formatted and indented freely
! some exceptions will be discussed later
4. Comments:
block comments /* */
and
line-ending comments //
5. Literals
a literal is a data value that appears directly in a program
Numeric Literals
String Literals
are used to name variables and functions and to provide labels for certain loops
must begin with a letter, an underscore (_), or a dollar sign
($)
followed by letters, digits, underscores, or dollar signs
! digits are not allowed as the first character so that JavaScript can easily distinguish identifiers from numbers
! for portability
and ease of editing use
only ASCII letters and digits in identifiers
even if it is allowed for identifiers to contain letters and
digits from the entire Unicode character set
are keywords reserved by the language itself, cannot be used as identifiers
Also avoid using predefined global variables and function names:
arguments Array NaN Number
Bolean Object
Date decodeURI decodeURIComponent parseFloat parseInt
encodeURI encodeURIComponent Error eval EvalError RangeError ReferenceError RegExp
Function String SyntaxError
Infinity isFinite isNaN TypeError
JSON undefined
Math
8. Optional Semicolons
like
in many programming languages, the semicolon (;) is used to separate
statements
from each other they => this is important in order to make the code clear.
It can usually be omitted :
! Not every line break is treated as a semicolon
JavaScript
treats a line break as a semicolon if the next non space character
cannot be interpreted as a continuation of the current statement
=>
if a statement begins with (, [, /, + or -, there is a chance
that it could be interpreted as a continuation of the statement before
! There are two exceptions to the general rule