Arithmetic | a = 12, b = 4 | ||||
+ - * / % ++ – – |
Addition Subtraction Multiplication Division Modulus Increment Decrement |
a a a a a a a |
+ - * / % ++ – – |
b b b b b |
16 8 48 3 0 13 11 |
Assignment | a = 12, b = 4 | ||||
= += -= *= /= %= |
Assign to Add and assign Subtract and assign Multiply and assign Divide and assign Modulus and assign |
a a a a a a |
= += -= *= /= %= |
b b b b b b |
b now equals 12 a now equals 4 a now equals 8 a now equals 48 a now equals 3 a now equals 0 |
Comparison | a = 12, b = 4 | ||||
== != > < >= <= |
Equality Inequality Greater than Less than Greater than or equal Less than or equal |
a a a a a a |
== != > < >= <= |
b b b b b b |
false true true false true false |
Logical | a = 12, b = 4 | ||||
&& || ! |
And OR NOT |
a a a |
&& || ! |
b b b |
true true !(a||b) = false reverses condition |
Conditional | a = 12, b = 4 | ||||
a > ? : | Ternary | a > b | ? car | : bike | car |
typeof
Unary operator placed before a single operand (which can be of any type) and returns true or false based on an evaluation or a string indicating the data type of the operand.
Number | "number" |
String | "string" |
Boolean | "boolean" |
Object | "object" |
Function | "function" |
Undefined | "undefined" |
Null | "object" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<html> <head> <title>JavaScript</title> </head> <body> <script type="text/javascript"> var a = 42; var b = "This is my car"; result = (typeof a == "string" ? "a is a string" : "a is a number"); document.write(result + "<br>"); //note use of + for concatenation document.write("b is a "); document.write(typeof b); </script> </body> </html> |
Save & refresh browser:
a is a number b is a string |