Check If Object Is Not Null | In Javascript
In JavaScript, typeof null famously returns "object" , which is a historical bug. To verify that a variable is a non-null object (and not an array or other primitive), use a combined check: javascript
Use this when you only care if the value is exactly null . It will return true even if the variable is undefined , 0 , or an empty string. javascript if (myObject !== null) { // Runs if myObject is NOT null } Use code with caution. Copied to clipboard 2. The "Nullish" Check (Recommended) Check If Object Is Not Null In Javascript
To check if an object is not null in JavaScript, use the strict inequality operator: if (myObject !== null) . In JavaScript, typeof null famously returns "object" ,