Question Bank

JavaScript Language Trivia

Difficulty: Easy

Beginner JS quirks to predict and explain: `==` vs `===`, hoisting, `this` binding in different call sites, and one quick closure trace.

Question Bank
/

JavaScript Language Trivia

JavaScript Language Trivia

Beginner JS quirks to predict and explain: `==` vs `===`, hoisting, `this` binding in different call sites, and one quick closure trace.

Question Bank
Easy
JavaScript
4 questions
js-hoisting
js-this
closures
quiz

1,142 views

23

Predict each line of output and explain why == returns true for some non-identical types while === does not.

Examples

Example 1:

Input: evaluate 0 == '', 0 == '0', '' == '0', null == undefined, null === undefined
Output: true, true, false, true, false
Explanation: == applies abstract equality with coercion toward Number for primitives. 0 == '' becomes 0 == 0. '' and '0' are both strings, no coercion, compared by content. null and undefined are abstract-equal only to each other by spec. === requires same type, so null === undefined is false.