Chapter 1: Values, Types, and Operators Flashcards
JavaScript expression for the remainder of 10 divided by 3
10 % 3
Three special numbers in JS
Infinity
-Infinity
NaN
Three ways to write a string in JS
“Double quotes”
‘Single quotes’Backticks
Escape character in JS
Backslash
String concatenation
+
What is a “template literal”?
A string which can embed a calculated or object value
How do you write a template literal?
Use backticks around text, with values to be computed surrounded by ${}
How to return to type of a value
With the “typeof” operator: typeof “string” -> string
JS “and” operator
&&
JS “or” operator
||
JS conditional operator (and example)
? :
false ? 7 : 3 -> 3
What is “type coercion?
When JS is told to use an operator on values of differing types, it will try to force on value to be the type of the other
How can you avoid false from getting automatically converted to 0 or “” in a comparison to a number or string?
Use === instead of == or !== instead of !=
What is “short-circuit evaluation”?
A behavior in JS in which the only value in an expression that is evaluated is the value that is selected; non-selected values are not evaluated
Give an example of short-circuit evaluation
true || “not selected” -> true