What happens with const v = a || b ?? "default";?
To avoid confusion about precedence, the language forbids mixing ?? with || or && unless you add parentheses: (a || b) ?? "default".
Operators · Exercise 1 of 4
Fifteen multiple-choice questions on JavaScript operators: == and ===, increments, && and || return values, ?? and ?., exponent associativity, in, instanceof, delete and Object.is. Pick an option to check your answer instantly.
What happens with const v = a || b ?? "default";?
To avoid confusion about precedence, the language forbids mixing ?? with || or && unless you add parentheses: (a || b) ?? "default".
What does the unary + do in +"42"?
Unary + is a short form of Number(): +"42" is 42, +"" is 0, +"4px" is NaN, +true is 1.
What does delete arr[1] do to const arr = [10, 20, 30];?
delete removes the property "1" but does not reindex. Node prints [ 10, <1 empty item>, 30 ]. Use arr.splice(1, 1) to remove and shift.
What does obj instanceof Car actually check?
instanceof walks obj's prototype chain looking for Car.prototype. That is why [] instanceof Object is true – Object.prototype is at the end of every normal chain.
For which pair of values do Object.is(a, b) and a === b give different results?
Object.is(NaN, NaN) is true but NaN === NaN is false. The other difference is +0 and -0 (=== true, Object.is false).
Timed online tests with instant scores and explanations.