Visit Mozilla.org

Core JavaScript 1.5 Guide:Expressions

From MDC


[edit] Expressions

An expression is any valid set of literals, variables, operators, and expressions that evaluates to a single value; the value can be a number, a string, or a logical value.

Conceptually, there are two types of expressions: those that assign a value to a variable, and those that simply have a value. For example, the expression x = 7 is an expression that assigns x the value seven. This expression itself evaluates to seven. Such expressions use assignment operators. On the other hand, the expression 3 + 4 simply evaluates to seven; it does not perform an assignment. The operators used in such expressions are referred to simply as operators.

JavaScript has the following types of expressions:

  • Arithmetic: evaluates to a number, for example 3.14159. (Generally uses Arithmetic operators.)
  • String: evaluates to a character string, for example, "Fred" or "234". (Generally uses String operators.)
  • Logical: evaluates to true or false. (Often involves Logical operators.)
  • Object: evaluates to an object. (See Special Operators for various ones that evaluate to objects.)

« Previous Next »