Values
- 18
- “hello”
- true
Numbers
- .18
- 1.8
- 18
- 18000000000000000000
- Infinity
- -Infinity
Strings
- “hello”
- ‘hello’
- `hello`
- “hello” + “hello” = “hellohello”
- template literals: `half of 100 is ${100 / 2}`
Operators (Unary, Binary, Ternary)
- 2 * 3
- 3 / 2
- 10 % 4
- 3 + 4
- 3 – 4
- -4
- typeof “something”
- !
- 3 < 4
- 3 > 4
- 3 < 4 && 3 > 4
- 3 < 4 || 3 > 4
- 3 !== 4
- 4 == 4
- 3 < 4 ? true : false
Boolean values
- true
- false
Empty values
- null
- undefined
Type Coercion
- 8 * null
- “5” – 1
- “5” + 1
- “five” * 2
- null == undefined
- null == 0
short-circuit evaluation
- 0 || -1
- “” || “!?”
- false && X
Summary
We looked at four types of JavaScript values in this chapter: numbers, strings, Booleans, and undefined values.
Such values are created by typing in their name (true
, null
) or value (13
, "abc"
). You can combine and transform values with operators. We saw binary operators for arithmetic (+
, -
, *
, /
, and %
), string concatenation (+
), comparison (==
, !=
, ===
, !==
, <
, >
, <=
, >=
), and logic (&&
, ||
), as well as several unary operators (-
to negate a number, !
to negate logically, and typeof
to find a value’s type) and a ternary operator (?:
) to pick one of two values based on a third value.