ECMAScript/JavaScript
An Introduction for Programmers |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
//
and the end of the line
is a comment/*
and a */
is a commenttrue
or false
Infinity
, NaN
,
Number.MAX_VALUE
, Number.MIN_VALUE
,
Number.NaN
, Number.POSITIVE_INFINITY
,
Number.NEGATIVE_INFINITY
\
is the escape character and can be used to
represent special characters (e.g., \n
represents
the newline character) and Unicode characters
(e.g., \u00e9
is é)undefined
+
)-
)*
)/
)/
)%
)++
) and Decrement (--
)-
)>
<
>=
<=
==
===
!=
!==
NaN
(i.e., NaN === NaN
always evaluates to false
)null == undefined
evaluates to true
true
becomes 1
and
false
becomes 0
)
&&
||
!
if
Statementwhile
Loopsdo-while
Loopsfor
Loopsnew
Operator:
.
in
Operator:
delete
Operator:
[]
Operator:
delete
Operator:
undefined
length
Property:
for of
Loops[]
operator more than oncetoString()
method) and then testType | Passed By | Compared By |
boolean | Value | Value |
number | Value | Value |
Object | Reference | Reference |
string | Immutable | Value |
f
):
undefined
Note: This is very different from, for example, var size =
area(3,5);
which executes area
.
f
is the same function as area
and can be
used the same way.
this
?this
refers to the global objectthis
refers to the "owning" objectnew
Operator:
this
to
refer to the object, and then invokes a functionRectangle
Pseudoclasswidth
and height
:
width
and height
area
:
area
functionRectangle
PseudoclasshasOwnProperty()
method can be
used to determine if the property is owned
by the object or its prototypein
operator can be used to determine
if an object has or appears to have a propertyBoolean
, Number
and
String
).
s
containing a string,
you can use methods like s.charAt(index)
n
containing a number,
you can use methods like n.toString(base)