ptg16476052
488 LESSON 17: Introducing JavaScript
Output ▼
Functions are called using the function name, followed by parentheses. If you are pass-
ing arguments to a function, they are included in the parentheses in a comma-separated
list. Even if you’re not using arguments, the parentheses are still required. This is true
whether you’re calling a function you wrote yourself or a function that’s built in to
JavaScript.
Data Types
I’ve mentioned JavaScript’s type system, but I haven’t talked much about JavaScript data
types. JavaScript supports the following types of values:
n Strings, like "Teach Yourself Web Publishing".
n Boolean values (true or false).
n Numbers, integer or decimal.
n null, which is used to represent an unknown or missing value.
n undefined, the value associated with variables that have been declared but have not
yet had a value assigned to them. Also the return value of methods that don’t return
anything.
This is the full set of primitive data types that JavaScript supports. JavaScript attempts to
convert data to whatever type it needs in a given context. So if you take a Boolean value
and use it in a context where a string is expected, JavaScript will convert it to a string.
In some cases, this automatic conversion process can lead to odd results. For example,
if you try to use a value that’s not a number in a context where a number is expected,
Ja vaScript will return a special value, NaN, which is short for “not a number”:
Math.sqrt("a string"); // The value of squareRoot is NaN
FIGURE 17.6
Values passed
to functions are
copies.