Salesforce Certified JavaScript Developer Practice Questions

Salesforce Certified JavaScript Developer exam preparation

Salesforce Certified JavaScript Developer practice questions in English: 180 questions with explanations. The mock exam has 60 questions and 105 minutes.

Salesforce Certified JavaScript Developer free question 2 / 10 · Domain 1: Variables, Types, and Collections

What does this code log? console.log(null == undefined, null === undefined, null == 0);

  1. false false false, because loose equality never treats two different types as equal
  2. true true false, because strict equality makes null and undefined the same value
  3. true true true, because null and undefined are both converted to zero before they are compared
  4. true false false, because loose equality only equates null with undefined and never with other values
Show the answer and explanation

Answer: D

Why this is correct
The Equality page's algorithm says that if one operand is null or undefined, the other must also be null or undefined to return true, and otherwise the result is false. So null == undefined is true and null == 0 is false. Strict equality compares types first, so null === undefined is false.

Why the other options are wrong
"true true true, because null and undefined are both converted to zero before they are compared" … The page's rule for null and undefined says the other operand must also be null or undefined. Zero is not, so the third comparison is false.
"false false false, because loose equality never treats two different types as equal" … Loose equality has a special rule that makes null and undefined equal to each other, so the first comparison is true.
"true true false, because strict equality makes null and undefined the same value" … Strict equality always considers operands of different types different, and null and undefined have different types, so the second comparison is false.

Key points
The null-undefined pairing is a special case of loose equality. It does not generalize to 0, the empty string, or false.

Go to the Salesforce Certified JavaScript Developer practice app (10 free questions; purchase unlocks all questions)

See the full practice set