Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What is the difference between == and === in JavaScript?

Do you know what will be the output of this code?

JavaScript
console.log(1 === "1", 1 == "1");
Show answer and explanation

The answer is false true.

=== (strict equality) compares type and value, and a number is never equal to a string. == (loose equality) converts the string "1" to the number 1 first, so the comparison is true.

Prefer === to avoid surprises.

Take the full quiz Next question →

More Basics questions

  1. What happens when you reassign a const in JavaScript?
  2. Why is typeof null "object" in JavaScript?
  3. What does Array.push() return in JavaScript?
  4. Is a var loop variable accessible after a for loop?
  5. Why does "5" * "2" equal 10 in JavaScript?

Related topics