|| returns the first _____ value.
?? returns the first _____ value.
|| returns the first truthy value.
?? returns the first defined value.
2) What would the console print?
let x = null; let y = 5; let z = null; let cube = x ?? 10 * y ?? 10 * z ?? 2 console.log(cube)
Since there are no parantheses, the multiplication takes precedence and we have
cube = null ?? 50 ?? null ?? 2
cube = 50 // as the first defined value is 50
3) What will the console print?
let cube = 1 ?? 2 && 3 console.log(cube)
&& as well as // are forbidden to be used alongside the nullish coalescing operater without
parentheses.
4) Which of the following has a syntax error?
A)
let printError = e => {
return e
}
B)
let printError = e => e
C)
let printError = e, v => v
D)
let printError = (e, v) => {
return v
}
For arrow functions, only when there is one or less arguments can the parantheses be left out.
5) What does the console print?
let sum = (a, b) => { console.log(a) console.log(b) return (a + b)
}
sum(1, 2)
A is the correct answer because only the two values get printed and the sum is returned to
nothing and therefore doesn't get printed.