Check null

2 snippets across 2 stacks — JavaScript, SQL

Also written as null check

JSJavaScript

typeof null and Other Gotchas

JS · Common Mistakes
syntax
typeof null === "object"  // true (historic bug)
typeof NaN === "number"   // true (NaN is a number type)
typeof [] === "object"    // true (arrays are objects)
example
// All of these are surprising but correct
console.log(typeof null);        // "object"
console.log(typeof NaN);         // "number"
console.log(typeof []);          // "object"
console.log(typeof function(){}); // "function"

// Better checks
console.log(value === null);           // null check
console.log(Number.isNaN(value));      // NaN check
console.log(Array.isArray(value));     // array check

Note typeof is unreliable for null, arrays, and NaN. Use specialized checks: === null, Array.isArray(), Number.isNaN(), or instanceof for specific types.

SQLSQL

IS NULL / IS NOT NULL

SQL · Filtering
syntax
WHERE column IS NULL
WHERE column IS NOT NULL
example
SELECT first_name, phone
FROM users
WHERE phone IS NOT NULL;
output
-- Users who have provided a phone number

Note Never use = NULL or <> NULL. These always evaluate to UNKNOWN and return no rows. NULL is not a value — it represents the absence of a value, so only IS NULL / IS NOT NULL work.