AJAX - The Complete Reference

(avery) #1

572 Part IV: Appendixes


We previously covered the type operators used for property access and remind you that
to access a property aProperty of an object object, the following two syntaxes are equivalent:

object.aProperty
object["aProperty"]

Note that the brackets are “real” brackets (they do not imply an optional component).

Comma Operator


The comma operator allows multiple statements to be carried out as one. The syntax of the
operator is

statement1, statement2 [, statement3] ...

The comma is commonly used to separate variables in declarations or parameters in function
calls. However, while uncommon, if this operator is used in an expression, its value is the
value of the last statement.

var x = (4,10,20);
alert(x); // 20

Operator Description Example
delete If the operand is an array element
or object property, the operand is
removed from the array or object.

var myArray = [1,3,5];
delete myArray[1];
alert(myArray);
// shows [1,,5]
instanceof Evaluates true if the first operand
is an instance of the second
operand. The second operand must
be an object (for example,
a constructor).

var today = new Date();
alert(today instanceof Date);
// shows true

in Evaluates true if the first operand
(a string) is the name of a property
of the second operand. The second
operand must be an object (for
example, a constructor).

var robot = {jetpack:true}
alert("jetpack" in robot);
// alerts true
alert("raygun" in robot);
// alerts false
new Creates a new instance of the
object given by the constructor
operand.

var today = new Date();
alert(today);

void Effectively undefines the value of
its expression operand.

var myArray = [1,3,5];
myArray = void myArray;
alert(myArray);
// shows undefined

TABLE A-16 Type-Related Operators
Free download pdf