-
Notifications
You must be signed in to change notification settings - Fork 103
Operators
kazuho edited this page Jul 2, 2012
·
21 revisions
The operators of JSX are the same to those in JavaScript (ECMA-262 3rd edition) except for the following changes.
- types of the operands accepted by the operators are more restrictive
- logical operators (&& ||) return boolean
- binary ?: operator has been introduced (to cover the use of || in JavaScript to return non-boolean values)
- introduction of the as operator
- delete is a statement instead of an operator
- a wrapper object (Boolean, Number, String) cannot become a left-hand-side expression
The table below lists the operators supported by JSX.
Operator | Returned Type | Operand Type(s) | Note |
---|---|---|---|
(x) | typeof x | grouping operator | |
(...) | returned type of the called function | function call | |
x.property | typeof x.property | x:Object | |
array[index] | Nullable.<T> | array: Array.<T>, index: number | |
map[key] | Nullable.<T> | map: Map.<T>, key: string | |
x++ | typeof x | number or int | |
x-- | typeof x | number or int | |
x instanceof y | boolean | x: Object, y: Class, Interface, Mixin | |
x as type | type | cast operator | |
x as __noconvert__ type | type | cast operator (without run-time type check) | |
++x | typeof x | number or int | |
--x | typeof x | number or int | |
+x | typeof x | number or int | |
-x | typeof x | number or int | |
~x | int | number or int | |
! x | boolean | any | |
typeof x | boolean | variant | |
x * y | number or int | number, int, Number | int is returned if both operands are int |
x / y | number or int | number, int, Number | int is returned if both operands are int |
x % y | number | number, int, Number | |
x + y | string | string or String | |
x + y | number or int | number, int, Number | int is returned if both operands are int |
x - y | number or int | number, int, Number | int is returned if both operands are int |
x << y | int | number, int, Number | |
x >> y | int | number, int, Number | |
x >>> y | int | number, int, Number | |
x < y | boolean | number, int, string, Number, String | |
x <= y | boolean | number, int, string, Number, String | |
x > y | boolean | number, int, string, Number, String | |
x >= y | boolean | number, int, string, Number, String | |
x in y | boolean | x: string, y: Map.<T> | |
x == y | boolean | boolean, number, int, string, Boolean, Number, String, Object | |
x != y | boolean | boolean, number, int, string, Boolean, Number, String, Object | |
x & y | int | number, int, Number | |
x ^ y | int | number, int, Number | |
x | y | int | number, int, Number | |
x && y | boolean | any | |
x || y | boolean | any | |
x ? y : z | typeof y | returned types of y and z should be equal | |
x ?: y | typeof x | returned types of x and y should be equal | |
x = y | typeof x | type of y should be convertible to type of x | |
x op= y | typeof x | same as op, except that x cannot be a wrapper object | op can be any of: * / % + - << >> >>> & ^ | |
x, y | typeof y |