Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SH20RAJ/2637af7a368318efa3bace43bfc98f36 to your computer and use it in GitHub Desktop.
Save SH20RAJ/2637af7a368318efa3bace43bfc98f36 to your computer and use it in GitHub Desktop.
is 0 !== null in Javascript πŸ’‘ - 🧐 JavaScript Quirks: Tricky Equality Questions! πŸ’‘

Title: "🧐 JavaScript Quirks: Exploring Tricky Equality Questions! πŸ’‘"

Have you ever wondered about the curious world of JavaScript equality comparisons? πŸ€” Brace yourself for a dive into some peculiar scenarios where JavaScript's loose equality rules can lead to surprising results! Let's explore these quirky questions together! πŸš€βœ¨

Question 1: What's the result of 0 == null? πŸ€”

console.log(0 == null); // ?
Answer:

The output is:

false

In JavaScript, null is only equal to undefined, not 0.

Question 2: How about 0 >= null? πŸ€”

console.log(0 >= null); // ?
Answer:

The output is:

true

This might seem odd, but in JavaScript, when >= is used with null, it is coerced to 0. So 0 >= null becomes 0 >= 0, which is true.

Question 3: What does 0 <= null return? πŸ€”

console.log(0 <= null); // ?
Answer:

The output is:

true

Similar to the previous question, <= with null coerces null to 0, making 0 <= null effectively 0 <= 0, which is true.

Question 4: How does false == null behave? πŸ€”

console.log(false == null); // ?
Answer:

The output is:

false

In JavaScript, false is not equal to null. They are of different types and values.

Question 5: What happens with false <= null? πŸ€”

console.log(false <= null); // ?
Answer:

The output is:

true

This is another case of coercion. false is coerced to 0 and null to 0, making 0 <= 0, which is true.

Question 6: Lastly, is false >= null true or false? πŸ€”

console.log(false >= null); // ?
Answer:

The output is:

true

Similar to the previous cases, both false and null are coerced to 0, so 0 >= 0 is true.

πŸš€ Ready for the JavaScript Quirks Adventure? πŸ’‘

JavaScript's loose equality comparisons can lead to some unexpected results! Keep these quirks in mind as you navigate the JavaScript landscape, and always test your code to understand what's happening under the hood! 🧐✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment