A

Admin • 833K Points
Coach

Q. The snippet that has to be used to check if “a” is not equal to “null” is _________

  • (A) if(a!==null)
  • (B) if(a!null)
  • (C) if (!a)
  • (D) if(a!=null)
  • Correct Answer - Option(A)
  • Views: 29
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

In JavaScript, we use !== (strict inequality operator) to check both:

  1. Value inequality
  2. Type inequality

Example: Checking if a is not null

var a = "Hello";  // Example value
if (a !== null) {
console.log("a is not null");
} else {
console.log("a is null");
}

Output:

a is not null

If a = null, then the condition fails.

Why Not Other Options?

  • (B) if(a!null) → ❌ Incorrect (invalid syntax; ! should be used with boolean expressions, not values).
  • (C) if(!a) → ❌ Incorrect (this checks if a is falsy, but 0, "", undefined, NaN, and false are also falsy, not just null).
  • (D) if(a != null) → ✅ Correct, but (A) is preferred because != does type coercion, whereas !== strictly checks for null.

Final Answer:

(A) if(a !== null) (Best practice for checking null).

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.