Basic HTML version of Foils prepared 23 June 1997

Foil 21 JavaScript Expressions - I

From JavaScript Tutorial for Certificate Course UC Web applications Certificate -- Summer 97. by Geoffrey C. Fox, Tom Scavo

Using = Instead of == in Comparison
JavaScript expressions and basic operators are similar to C, PERL, and Java
Assignment operators:
= += -= *= /= %= <<= >>= >>>= &= ^= |=
  • x += y; // means x = x + y
  • x %= y; // means x = x % y (i.e., x mod y)
Conditional expressions are supported:
  • status = (age >= 18) ? "adult" : "minor"; /* sets status to "adult" if age is greater than or equal to 18; otherwise set to "minor" */
Arithmetic operators are as usual with the addition of ++ and --
  • y = ++x; // increments x; assigns this value to y



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998