Data Types
Primitives
number
- While many languages have multiple types for representing numbers (integers, single precision, double precision, long integers, etc.), all Javascript numbers are double precision floating point numbers.
string
- Javascript strings are similar to other languages, they can be created with single quotes, double quotes, or backticks
boolean
- True or False
array
- A list of values, Started and ended with brackets, and delimited with commas
object
- A list of key value pairs. Started and ended with braces, delimited with commas, and with colons separating keys from values
5
24.7
2.7e5
0b0010
0o0010
0x0010
"I'm a string"
'I have "double quotes"'
`I'm a string with "double quotes"
and multiple lines`
true
false
[]
[ 5 ]
[
24,
25,
26,
]
[ [5], {"yay": 5}, null, undefined, 6, "no", true ]
{}
{ "key": "value" }
{ 5: 6 }
{ 5: { 6: 7 } }
Operators
Arithmetic
+ - Addition
- - Subtraction
/ - Division
* - Multiplication
** - Exponentiation
% - Modulus (Division Remainder)
4 + 3
"4" + "3"
4 - 3
4 / 3
4 * 3
4 ** 3
4 % 3
Assignment
= - Assigns a value to a variable
+= - Shorthand for x = x + y
-= - Shorthand for x = x - y
*= - Shorthand for x = x * y
/= - Shorthand for x = x / y
%= - Shorthand for x = x % y
**= - Shorthand for x = x ** y
++ - Shorthand for x = x + 1
-- - Shorthand for x = x - 1
x = 5
x += 5
x -= 5
x *= 5
x /= 5
x %= 3
x **= 3
x++
x--
Comparison
== - Equal value
=== - Equal value and type
!= - Not equal value
!== - Not equal value or type
> - Greater than
< - Less than
>= - Greater than or equal to
<= - Less than or equal to
? - Used in conjunction with a colon. If the first value is true, then the expression is equivalent to the second value. Otherwise the expression is equivalent to the third value.
"5" == 5
"5" != 4
5 === 5
"5" !== 5
5 > 4
4 < 5
5 >= 5
5 <= 5
5 == 5 ? 4 : 3
Logic
&& - And
|| - Or
! - Not
true && true
true || false
!false
true && false
false || false
!true
Bit Manipulation
& - And
| - Or
^ - Xor
~ - Not
<< - Left Shift
>> - Right Shift
>>> - Unsigned Right Shift
0b0110 & 0b0011
0b0110 | 0b0011
0b0110 ^ 0b0011
~ 0b0011
0b0110 << 1
0b0110 >> 1