JavaScript 2.0
Core Language
Expressions
previousupnext

Thursday, November 11, 1999

Most of the behavior of expressions is the same as in JavaScript 1.5. Differences are highlighted below. One general difference is that most expression operators can be overridden via operator overloading.

b  {allowInnoIn}

Identifiers

Identifier 
   Identifier
|  box
|  constructor
|  field
|  get
|  language
|  local
|  method
|  set
|  override
|  version

The above keywords are not reserved and may be used in identifiers.

QualifiedIdentifier 
   Identifier
|  QualifiedIdentifier :: Identifier
|  ParenthesizedExpression :: Identifier

Just like in ECMAScript Edition 3, an identifier evaluates to an internal data structure called a reference. However, JavaScript 2.0 references have several additional attributes, one of which is a namespace. The namespace is set to the value of the ParenthesizedExpression. If the ParenthesizedExpression is a simple Identifier or QualifiedIdentifier then the parentheses may be omitted.

Primary Expressions

PrimaryExpression 
   null
|  true
|  false
|  Number
|  Number [no line break] String
|  String
|  this
|  super
|  QualifiedIdentifier
|  ? Identifier
|  RegularExpression
|  ParenthesizedExpression
|  ParenthesizedExpression [no line break] String
|  ArrayLiteral
|  ObjectLiteral
|  FunctionExpression
ParenthesizedExpression  ( ExpressionallowIn )

A Number literal or ParenthesizedExpression followed by a String literal is a unit expression. The unit object specified by the String is looked up; the result is called as a function and passed two arguments: the numeric value of the Number literal or ParenthesizedExpression, and either null (if a ParenthesizedExpression was provided) or the original Number literal expressed as a string.

The string representation allows user-defined unit classes to define extended syntaxes for numbers. For instance, a long-integer package might define a unit called "L" that treats the Number literal as a full 64-bit number without rounding it to a double first.

A ? Identifier expression is used to access scope information.

Function Expressions

FunctionExpression 
   AnonymousFunction
|  NamedFunction

Object Literals

ObjectLiteral 
   { }
|  { FieldList }
FieldList 
   LiteralField
|  FieldList , LiteralField
LiteralField  FieldName : AssignmentExpressionallowIn
FieldName 
   QualifiedIdentifier
|  String
|  Number

Array Literals

ArrayLiteral  [ ElementList ]
ElementList 
   LiteralElement
|  ElementList , LiteralElement
LiteralElement 
   «empty»
|  AssignmentExpressionallowIn

Postfix Unary Operators

PostfixExpression 
   FullPostfixExpression
|  ShortNewExpression
FullPostfixExpression 
   PrimaryExpression
|  FullNewExpression
|  FullPostfixExpression MemberOperator
|  FullPostfixExpression Arguments
|  PostfixExpression [no line break] ++
|  PostfixExpression [no line break] --
FullNewExpression  new FullNewSubexpression Arguments
ShortNewExpression  new ShortNewSubexpression
FullNewSubexpression 
   PrimaryExpression
|  FullNewSubexpression MemberOperator
|  FullNewExpression
ShortNewSubexpression 
   FullNewSubexpression
|  ShortNewExpression
MemberOperator 
   [ ArgumentList ]
|  . QualifiedIdentifier
|  . ParenthesizedExpression
|  @ QualifiedIdentifier
|  @ ParenthesizedExpression

The @ operator performs a type cast. The second operand specifies the type. Both the . and the @ operators accept either a QualifiedIdentifier or a ParenthesizedExpression as the second operand. If it is a ParenthesizedExpression, the second operand of . must evaluate to a string. a.(x) is a synonym for a[x] except that the latter can be overridden via operator overloading.

The [] operator can take multiple (or even named) arguments. This allows users to define data structures such as multidimensional arrays via operator overloading.

Arguments  ( ArgumentList )
ArgumentList 
   «empty»
|  ArgumentListPrefix
|  NamedArgumentListPrefix
ArgumentListPrefix 
   AssignmentExpressionallowIn
|  ArgumentListPrefix , AssignmentExpressionallowIn
NamedArgumentListPrefix 
   LiteralField
|  ArgumentListPrefix , LiteralField
|  NamedArgumentListPrefix , LiteralField

An ArgumentList can contain both positional and named arguments. Named arguments use the same syntax as object literals.

Prefix Unary Operators

UnaryExpression 
   PostfixExpression
|  delete PostfixExpression
|  typeof UnaryExpression
|  eval UnaryExpression
|  ++ PostfixExpression
|  -- PostfixExpression
|  + UnaryExpression
|  - UnaryExpression
|  ~ UnaryExpression
|  ! UnaryExpression

Multiplicative Operators

MultiplicativeExpression 
   UnaryExpression
|  MultiplicativeExpression * UnaryExpression
|  MultiplicativeExpression / UnaryExpression
|  MultiplicativeExpression % UnaryExpression

Additive Operators

AdditiveExpression 
   MultiplicativeExpression
|  AdditiveExpression + MultiplicativeExpression
|  AdditiveExpression - MultiplicativeExpression

Bitwise Shift Operators

ShiftExpression 
   AdditiveExpression
|  ShiftExpression << AdditiveExpression
|  ShiftExpression >> AdditiveExpression
|  ShiftExpression >>> AdditiveExpression

Relational Operators

RelationalExpressionallowIn 
   ShiftExpression
|  RelationalExpressionallowIn < ShiftExpression
|  RelationalExpressionallowIn > ShiftExpression
|  RelationalExpressionallowIn <= ShiftExpression
|  RelationalExpressionallowIn >= ShiftExpression
|  RelationalExpressionallowIn instanceof ShiftExpression
|  RelationalExpressionallowIn in ShiftExpression
RelationalExpressionnoIn 
   ShiftExpression
|  RelationalExpressionnoIn < ShiftExpression
|  RelationalExpressionnoIn > ShiftExpression
|  RelationalExpressionnoIn <= ShiftExpression
|  RelationalExpressionnoIn >= ShiftExpression
|  RelationalExpressionnoIn instanceof ShiftExpression

Equality Operators

EqualityExpressionb 
   RelationalExpressionb
|  EqualityExpressionb == RelationalExpressionb
|  EqualityExpressionb != RelationalExpressionb
|  EqualityExpressionb === RelationalExpressionb
|  EqualityExpressionb !== RelationalExpressionb

Binary Bitwise Operators

BitwiseAndExpressionb 
   EqualityExpressionb
|  BitwiseAndExpressionb & EqualityExpressionb
BitwiseXorExpressionb 
   BitwiseAndExpressionb
|  BitwiseXorExpressionb ^ BitwiseAndExpressionb
|  BitwiseXorExpressionb ^ *
|  BitwiseXorExpressionb ^ ?
BitwiseOrExpressionb 
   BitwiseXorExpressionb
|  BitwiseOrExpressionb | BitwiseXorExpressionb
|  BitwiseOrExpressionb | *
|  BitwiseOrExpressionb | ?

Binary Logical Operators

LogicalAndExpressionb 
   BitwiseOrExpressionb
|  LogicalAndExpressionb && BitwiseOrExpressionb
LogicalXorExpressionb 
   LogicalAndExpressionb
|  LogicalXorExpressionb ^^ LogicalAndExpressionb

The ^^ operator is a logical exclusive-or operator. It evaluates both operands. If they both convert to true or both convert to false, then ^^ returns false; otherwise ^^ returns the unconverted value of whichever argument converted to true.

LogicalOrExpressionb 
   LogicalXorExpressionb
|  LogicalOrExpressionb || LogicalXorExpressionb

Conditional Operator

ConditionalExpressionb 
   LogicalOrExpressionb
|  LogicalOrExpressionb ? AssignmentExpressionb : AssignmentExpressionb
NonAssignmentExpressionb 
   LogicalOrExpressionb
|  LogicalOrExpressionb ? NonAssignmentExpressionb : NonAssignmentExpressionb

Assignment Operators

AssignmentExpressionb 
   ConditionalExpressionb
|  PostfixExpression = AssignmentExpressionb
|  PostfixExpression CompoundAssignment AssignmentExpressionb
CompoundAssignment 
   *=
|  /=
|  %=
|  +=
|  -=
|  <<=
|  >>=
|  >>>=
|  &=
|  ^=
|  |=
|  &&=
|  ^^=
|  ||=

Expressions

Expressionb 
   AssignmentExpressionb
|  Expressionb , AssignmentExpressionb
OptionalExpression 
   ExpressionallowIn
|  «empty»

Type Expressions

TypeExpressionb  NonAssignmentExpressionb

Waldemar Horwat
Last modified Thursday, November 11, 1999
previousupnext