Compare values

2 snippets across 2 stacks - JavaScript, SQL

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.

SQLSQL

Comparison Operators

SQL · Filtering
Syntax
WHERE column = | <> | < | > | <= | >= value
Example
SELECT product_name, price
FROM products
WHERE price >= 50.00 AND price < 200.00;
Output
-- Products priced from 50 up to (not including) 200

Note Use <> for not-equal (ANSI standard). != works in MySQL and PostgreSQL but is not part of the standard.

Frequently asked questions

How do you compare values?
This task is covered in 2 stacks on this page: JavaScript, SQL. 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 "compare values" on this page?
JavaScript, SQL. Together they hold 2 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.