Binary vs. Unary
Operators:
- Binary:
operand operator operand, Ex. x + y, x = 1
- Unary:
- operator
operand: ! isOK, ++i
- operand
operator: i++
Operators:
Assignment |
=, +=, -=, *=, %=,
/=, ... |
Comparison |
<, >, <=,
>=, ==, != |
Arithmetic |
+, -, ++, --, *, /,
% |
Bitwise |
~, <<,
>>, >>>, &, |, ^ |
Logical |
&&, ||, ! |
String |
+, += |
Special operators |
? :, delete, new,
typeof, void |
|
Special Operators
(condition) ? val1 : val2
var1 = 3;
var2 = (var1 >= 0) ? "Positive" : "Negative";
// Now var2 is "Positive".
- delete
- Deletes a property from an object, or removes an
element from an array.
delete obj1.propertX;
delete arr[6];
- new
- Create an instance of an object.
The type of the object can be of user-defined or
one of the object types: Array , Boolean ,
Date , Function , Image ,
Number , Object , Option ,
RegExp , or String .
Example 1:
function area() {
return this.radius*this.radius*3.14159;
}
function myCircle(x,y,r) {
this.x_axis=x;
this.y_axis=y;
this.radius=r;
this.area=area;
}
cir = new myCircle(100,100,25);
ar1 = cir.area();
Example 2:
img1=new Image();
img1.src="icon1.gif";
- typeof
- Returns a string indicating the type of the
operand.
Possible returned string: "object", "number", "string", "boolean", "function", "undefined"
var today=new Date();
typeStr = typeof today; // or typeof(today)
// Now typeStr is "object".
- void
- The void operator is used in
either of the following ways:
1. javascript:void (expression)
2. javascript:void expression
The void operator specifies
an expression to be evaluated without returning a
value.
|