== vs ===

3 snippets across 2 stacks - JavaScript, Python

Also written as == vs is

JSJavaScript

Equality: == vs === vs Object.is

JS · Data Types
Syntax
a === b   // strict (no coercion)
a == b    // loose (with coercion)
Object.is(a, b)  // same-value equality
Example
console.log(0 == false);         // true
console.log(0 === false);        // false
console.log(NaN === NaN);        // false
console.log(Object.is(NaN, NaN)); // true
console.log(Object.is(0, -0));    // false

Note Always use === for comparisons. Object.is() handles edge cases like NaN and -0 that even === gets wrong.

== vs === Confusion

JS · Common Mistakes
Syntax
// Wrong: == with type coercion
// Right: === for strict comparison
Example
// These all evaluate to true (unexpected!)
console.log("" == false);    // true
console.log(0 == "");        // true
console.log(null == undefined); // true
console.log("0" == false);   // true

// Use strict equality
console.log("" === false);   // false
console.log(0 === "");       // false
console.log(null === undefined); // false

Note Rule of thumb: always use === and !==. The only acceptable == use is value == null to check both null and undefined at once.

PYPython

is vs == (Identity vs Equality)

PY · Common Mistakes
Syntax
a == b  # equal values
a is b  # same object
Example
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
print(a is b)

# CPython caches small integers
x = 256
y = 256
print(x is y)

x = 257
y = 257
print(x is y)  # May be False!
Output
True
False
True
False

Note Use == for value comparison. Use 'is' only for None, True, False, or when you specifically need identity checks. CPython caches integers -5 to 256, making 'is' unreliable for numbers.

Frequently asked questions

How does JavaScript handle == vs ===?
This task is covered in 2 stacks on this page: JavaScript, Python. The "Equality: == vs === vs Object.is" snippet in JavaScript uses `a === b // strict (no coercion)`.
Which code does the JavaScript example use?
The "Equality: == vs === vs Object.is" snippet uses `a === b // strict (no coercion)`, from the Data Types section of the JavaScript cheat sheet.
Which stacks cover "== vs ===" on this page?
JavaScript, Python. Together they hold 3 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Equality: == vs === vs Object.is": Always use === for comparisons. Object.is() handles edge cases like NaN and -0 that even === gets wrong.