== 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.