In this article, I'd like to cover briefly the JavaScript operators. JavaScript operators can be grouped into 3 categories: unary, binary, and ternary operator.
1 Unary Operator
The unary operator only requires 1 value in order to invoke it. The unary operator takes form of both symbols and word. Its members are as follows:
- delete
- void
- typeof
- increment (both prefix and postfix): ++
- decrement (both prefix and postfix): --
- positive sign (convert to number): +
- negative sign (negate number): -
- bitwise NOT: ~
- logical NOT: !
The binary operator would need 2 values in order to evaluate its results: one value before the operator and one value after the operator. The members of the binary operator category can be grouped further by its capability:
- Arithmetic Operator
- Multiplicative Operator
- Multiplication: *
- Division: /
- Modulo: %
- Additive Operator
- Addition: +
- Subtraction: -
- Bitwise Operator
- Bitwise Shift Operator
- Left Shift: >>
- Right Shift: <<
- Unsigned Right Shift: >>>
- Binary Bitwise Operator
- Bitwise AND: &
- Bitwise XOR: ^
- Bitwise OR: |
- Binary Logical Operator
- Logical AND: &&
- Logcal OR: ||
- Relational Operator
- Less-than: <
- Greater-than: <
- Less-than-or-equal: <=
- Greater-than-or-equal: >=
- Instanceof: instanceof
- In: in
- Equality Operator
- Equal: ==
- Does-not-equal: !=
- Strict-equal: ===
- Strict-does-not-equal: !==
- Assignment Operator
- Simple assignment: =
- Compound assignment: +=, -=, %=, *=, /=, &=, ^=, |=
- Comma Operator
- Short summary: op1, op2 where op1 will always be executed but the result will be discarded, and the results of op2 will be the returned value of the comma operator.
The ternary operator works on 3 values and it only has one member, the question mark and colon operator:
var answer = true ? "True" : "False";The ternary operator is also known as the conditional operator.
I will discuss most of these operators in future posts.
No comments:
Post a Comment