HTML and CSS Reference
In-Depth Information
TABLE 4-2 JavaScript built-in objects
Function
Description
Gets code in the form of a string and executes it on the fly.
eval
Encodes and decodes special characters in a plain string.
escape / unescape
Encodes and decodes special characters in a URI string.
encodeUri / decodeUri
Returns true if the specified value is Not-A-Number.
isNaN
Returns true if the specified value is infinity.
isFinite
Parses a string and tries to extract an integer number out of it.
parseInt
Parses a string and tries to extract a floating point number out of it.
parseFloat
It should be noted that any object, value, or constant you happen to use in your JavaScript coding
that doesn't seem to belong to any objects of yours is ultimately available because it's exposed by the
global JavaScript object.
Null vs. undefined
When it comes to null-ness, JavaScript introduces a subtle difference that many higher-level
languages such as C# and Java miss. As you'll see more in detail in a moment, a JavaScript variable
is not bound to a fixed type. Subsequently, the variable is not bound to any type until it is explicitly
assigned a value. At this stage, the type of the variable is said to be undefined .
In JavaScript, undefined is seen as a special type rather than as a value. If you check the type of an
unassigned variable using the typeof operator, you get the string undefined . If you instead attempt to
evaluate the content of an unassigned variable, you get null . Pay attention to the following code:
var x; // therefore the type of the variable is "undefined"
var y = null;
What happens if you compare x and y ?
JavaScript has two equality operators: the double equals sign ( ==) operator and the triple equals
sign ( ===) operator. If you use the == operator, both expressions are evaluated and the resulting
values are compared. However, if you use the === operator, then the types of the values are also
compared. In reference to the previous code snippet, if you compare x and y using the == operator
then you get true, meaning that the undefined value of x ultimately evaluates to null , which matches
the value assigned to y .
In contrast, if you compare x and y using the === operator, then you get false : the two variables
hold the same value but are of different types.
 
Search WWH ::




Custom Search