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.

Frequently asked questions

How do you check null?
This task is covered in 2 stacks on this page: JavaScript, SQL. The "typeof null and Other Gotchas" snippet in JavaScript uses `typeof null === "object" // true (historic bug)`.
Which code does the JavaScript example use?
The "typeof null and Other Gotchas" snippet uses `typeof null === "object" // true (historic bug)`, from the Common Mistakes section of the JavaScript cheat sheet.
Which stacks cover "check null" on this page?
JavaScript, SQL. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "typeof null and Other Gotchas": typeof is unreliable for null, arrays, and NaN. Use specialized checks: === null, Array.isArray(), Number.isNaN(), or instanceof for specific types.