EcmaScript is an object-based scripting language for client and server applications. EcmaScript is the standardized version of JavaScript and behaves the same way in all applications that support the standard. JavaScript implementations correspond to the ECMA-262 Language Specification standardized by the European standards body.
Rhino 1.5, one of the supported JSTL EL's, implements JavaScript 1.5, which conforms to Edition 3 of the EcmaScript Standard. Rhino is an open source Java implementation of JavaScript.
Name | Links | Date | Description |
---|---|---|---|
ECMA-262
|
June 1997
|
The original ECMAScript standard.
|
|
ECMA-262 Edition 2
|
August 1998
|
The second revision of the ECMAScript standard; also ISO
standard 16262.
|
|
ECMA-262 Edition 3
|
December 1999
|
The third, and most recent, revision of the ECMAScript
standard. Corresponds to JavaScript 1.5.
|
|
Proposed EcmaScript Edition 4
|
?
|
JavaScript 2.0 is the next version of the JavaScript language. It closely matches the ECMAScript Edition 4 standard under development. The intent is to make JavaScript 2.0 and ECMAScript Edition 4 be the same language. |
This document gives a brief overview of the main EcmaScript features a page author may be interested in.
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, a logical
value, or an object.
EcmaScript has the following types of expressions:
The following operators should be of interest to a page author.
A comparison operator compares its operands and returns a logical value based on whether the comparison is true. The operands can be numerical, string, logical, or object values. Strings are compared based on standard lexicographical ordering, using Unicode values.
Operator | Description |
---|---|
Equal (==)
|
Returns true if the operands are equal.
|
Not equal (!=)
|
Returns true if the operands are not equal.
|
Strict equal (===)
|
Returns true if the operands are equal and of the same
type.
|
Strict not equal (!==)
|
Returns true if the operands are not equal and/or not
of the same type.
|
Greater than (>)
|
Returns true if the left operand is greater than the right
operand.
|
Greater than or equal (>=)
|
Returns true if the left operand is greater than or equal
to the right operand.
|
Less than (<)
|
Returns true if the left operand is less than the right
operand.
|
Less than or equal (<=)
|
Returns true if the left operand is less than or equal
to the right operand.
|
Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. These operators work as they do in most other programming languages, except the / operator returns a floating-point division in EcmaScript, not a truncated division as it does in languages such as C or Java.
Operator | Description |
---|---|
% (Modulus) |
Binary operator. Returns the integer remainder of dividing
the two operands.
|
++ (Increment)
|
Unary operator. Adds one to its operand. Can be used as
a prefix or postfix operator.
|
-- (Decrement)
|
Unary operator. Subtracts one to its operand. Can be used
as a prefix or postfix operator.
|
- (Unary negation)
|
Unary operator. Returns the negation of its operand.
|
Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the && and || operators return the value of one of the specified operands.
Operator | Usage | Description |
---|---|---|
Logical AND
|
expr1 && expr2
|
Returns expr1 if it can be converted to false; otherwise,
returns expr2.
|
Logical OR
|
expr1 || expr2
|
Returns expr1 if it can be converted to true; otherwise,
returns expr2.
|
Logical NOT
|
!expr
|
Returns false if its single operand can be converted to
true; otherwise, returns true.
|
In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.
Some special operators of interest:
Operator | Usage | Description |
---|---|---|
conditional
|
condition ? val1 : val2
|
The conditional operator can have one of two values based
on a condition.
|
in
|
val in Object
|
The in operator returns true if the specified property
is in the specified object.
|
The reserved words in this list cannot be used as EcmaScript variables, functions, methods, or object names.
abstract |
else
|
instanceof
|
switch
|
boolean
|
enum
|
int
|
synchronized
|
break
|
export
|
interface
|
this
|
byte
|
extends
|
long
|
throw
|
case
|
false
|
native
|
throws
|
catch
|
final
|
new
|
transient
|
char
|
finally
|
null
|
true
|
class
|
float
|
package
|
try
|
const
|
for
|
private
|
typeof
|
continue
|
function
|
protected
|
var
|
debugger
|
goto
|
public
|
void
|
default
|
if
|
return
|
volatile
|
delete
|
implements
|
short
|
while
|
do
|
import
|
static
|
with
|
double
|
in
|
super
|
Values passed from Java to JavaScript are converted as follows:
Java Types | Converted JavaScript Types |
---|---|
byte, char, short, int, long, float, and double
|
JavaScript numbers. Instances of java.lang.Double and
java.lang.Integer are converted to JavaScript objects, not to JavaScript
numbers.
|
boolean
|
JavaScript boolean
|
arrays
|
JavaScript pseudo-Array object
|
Java object of any other class
|
JavaScript wrapper
|
When you are evaluating JavaScript code in Java, the following situations can cause run-time errors:
The JavaScript interpreter generates an error message that is converted into an instance of JSException.
JavaScript throws an exception that is wrapped as an instance of JSException. Use the getWrappedException method of JSException to unwrap this exception in Java.