HTML and CSS Reference
In-Depth Information
Whitespace is preserved when it is embedded within a string or regular expression.
For example, the whitespace in the string, “Hello there” will be preserved because
it is enclosed within double quotes. Of course, you can't break up a word such as switch ,
if , else , window , document , and so on, because it would no longer be the same word.
Because extra whitespace is ignored by the JavaScript interpreter, you are free to indent,
break lines, and organize your program so that it is easier to read and debug.
There are a number of reserved words (also called keywords) in JavaScript. Being
reserved means that keywords are special vocabulary for the JavaScript language and can-
not be used by programmers as identifiers for variables, functions and labels, and the like.
Words such as if , for , while , return , null , and typeof are examples of reserved words.
Table 2.1 gives a list of reserved words.
Table 2.1 Reserved Keywords
abstract
boolean
bre a k
byte
case
catch
char
class
const
continue
default
delete
do
double
else
extends
false
final
finally
float
for
function
goto
if
implements
import
in
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
typeof
var
void
volatile
while
with
2.2.3 Statements and Semicolons
Just like sentences (which represent complete thoughts) in the English language, Java-
Script statements are made up of expressions. The statements are executed top down,
one statement at a time. If there are multiple statements on a line, the statements must
be separated by semicolons. Although not a rule, it is good practice to terminate all state-
ments with a semicolon to make it clear where the statement ends. Because JavaScript is
free form, as long as statements are terminated with a semicolon, the lines can be bro-
ken, contain whitespace, and so on. A statement results in some action unless the state-
ment is a null statement, in which case it does nothing.
The following two lines are both technically correct:
var name = "Ellie"
<- no semicolon, valid
var name = "Ellie" ;
<- better
 
 
Search WWH ::




Custom Search