typeofnull==="object"// true (historic bug)typeofNaN==="number"// true (NaN is a number type)typeof[]==="object"// true (arrays are objects)
Example
// All of these are surprising but correctconsole.log(typeofnull);// "object"console.log(typeofNaN);// "number"console.log(typeof[]);// "object"console.log(typeoffunction(){});// "function"// Better checksconsole.log(value ===null);// null checkconsole.log(Number.isNaN(value));// NaN checkconsole.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.
SELECT first_name, phone
FROM users
WHERE phone ISNOTNULL;
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.