HTML and CSS Reference
In-Depth Information
EXAMPLE
9.33 (
CONTINUED
)
document.write("The value of NaN is boolean " + bool5
+ "<br />");
</script>
</small>
</font>
</body>
</html>
EXPLANATION
1
The argument passed to the
Boolean
object constructor is the initial value of the
object, either
true
or
false
. If the initial value is
0
, the empty string
“”
,
NaN
, or
null
,
the result is
false
; otherwise, the result is
true
.
2
The
Boolean
object's values are displayed as either
true
or
false
(see Figure 9.38).
Figure 9.38
True
or
False
? Output from Example 9.33.
The
Function
object lets you define a function as an object. It allows a string to be
defined at runtime and then compiled as a function. You can use the
Function()
con-
structor to create a variable that contains the function. Because the function has no
name, it is often called an anonymous function and its arguments are passed as comma-
separated strings. The last argument is the body of statements that will be executed
when the function is called. If the
Function()
constructor does not require arguments,
then the body of statements is treated as a string, and will be passed to the
Function()
constructor to define what the function is to do. Because functions are objects, they also
have properties (see Table 9.13) and methods (see Table 9.14).
Function
objects are evaluated each time they are used, causing them to be slower in
execution than normal JavaScript functions.
Table 9.13
Properties of the
Function
Object
Property
What It Does
length
Returns the number of arguments that are expected to be passed (read only).
prototype
Allows the object to be customized by adding new properties and methods.