Evaluating Expressions
We've already talked about expressions--single lines of script that give values to variables or objects or other data containers, or manipulate those data containers using methods (like a sentence or a noun-adjective combination). When we run those expressions in JavaScript, the software evaluates the expressions and plugs the proper values into the data containers.
For example, if we declare and initialize a variable:
var myAge = 28
the software knows that the value of myAge is 28. When we use that variable, JS evaluates its value and properly uses it. So we can then write:
myAge -10
and the software should correctly evaluate the statement as 18.
Netscape has a special feature where you can evaluate an expression before you load it into an HTML page and run it. In other words, you can write one line of code and then test it without going through the whole process. Here's how to do it:
Try it. Go through these steps, and then enter var myAge = 28, hit RETURN, then type myAge - 10 and hit RETURN. You should then see 18 in the upper screen.