The purpose of this series of lessons is to teach you how to program in JavaScript. The goal is to provide a programming tutorial that will be accessible to persons with no programming experience and will be equally useful to persons who already have programming experience using JavaScript or some other language.
Earlier lessons have discussed function calls, literal values, and variables. Now we need to take a closer look at how they may be combined with operators to create expressions.
This lesson will concentrate on expressions. A subsequent lesson will concentrate on operators.
The resulting value can be a number, a string, or a logical (boolean) value.
Expressions can be very simple or very complex, depending on the need.
Some expressions are used to assign a value to a variable. For
example, the following box shows two expressions that assign a value to
the variable named myVar. The first expression is a simple
assignment which assigns a literal value to a variable. The second
expression is much more complex.
myVar = 10 myVar = ((6 + x) + myFunction(z))/Q |
For example, the second expression from above is repeated below.
myVar = ((6 + x) + myFunction(z))/Q |
JavaScript supports three types of expressions which match the three types of data described in an earlier lesson.
According to Netscape, there are a couple of subtle issues involving expressions.
The special keyword null denotes a null value. This is in contrast to variables that have not been assigned a value. Such variables are undefined and will cause a runtime error if used as numbers or as numeric variables.
On the other hand, array elements that have not been assigned a value evaluate to the boolean value false. We will discuss this in more detail when we discuss arrays.
Most of the lessons in this tutorial will contain one or more sample scripts that illustrate the material in this lesson. However, we will forego the sample script in this lesson because virtually every other sample script in every other lesson will contain one or more expressions. There will be no shortage of sample scripts containing expressions.
-end-