variable === undefined vs. typeof variable === “undefined” in JavaScript Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Undefined comes into the picture when any variable is defined already but not has been assigned any value. Undefined is not a keyword. A function can also be undefined when it doesn't have the value returned. There are two ways to determine if a variable is not defined, Value and type. var geeks; alert ( geeks === undefined) It's so clear that you assigned a variable that was not defined but the variable exists. Here you are comparing the geeks variable with the global variable "undefined" which is undefined also. Syntax: Check by Value (Strict equality Operator): Here you will get whether the variable is assigned a value or not if the variable is not assigned a value it will display undefined.Check the type (Typeof operator): Here you will get what type of variable was that if there is no variable assigned then it will display "undefined". Note: The strict equality operator (===) doesn't check whether the variable is null or not. The type of operator does not throw an error if the variable has not been declared. Example: Here we assign two variables one is undefined and the other one is defined as "null", here null is not undefined when you put console.log it will show "null" if you check typeof then it will display the object, below program will illustrate the approach more clearly. javascript var firstName; var lastName = null; // Print: undefined console.log(firstName); // Print: null console.log(lastName); // Print: undefined console.log(typeof firstName); // Print: object console.log(typeof lastName); // Print: false console.log(null === undefined) if(firstName === undefined) { console.log('LastName is undefined'); } else if(firstName === null){ console.log('FirstName is null'); } Output: undefined null undefined object false variable === undefined VS typeof variable === "undefined" variable === undefined typeof variable === "undefined" Here the assigned variables don't have any value but the variable exists.Here the type of variable is undefined.If you assigned a value(var geeks === undefined ) it will show, if not it will also show undefined but in different meaning.Here the undefined is the typeof undefined.In this, null will display if you assigned null to a variable, null is loosely equals to undefinedBut here typeof will show object. Comment More infoAdvertise with us Next Article Differences Between Undeclared and Undefined Variables in JavaScript A abhishek7 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads What are undeclared and undefined variables in JavaScript? Undefined: It occurs when a variable has been declared but has not been assigned any value. Undefined is not a keyword. Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using the var or const keyword. If we use 'typeof' operator to get the value of 1 min read Differences Between Undeclared and Undefined Variables in JavaScript In JavaScript, variables are declared using keywords like var, let, or const. The scope and behavior of variables depend on how they are declared:var: Has function scope or global scope. If not declared explicitly, a var variable becomes an undeclared global variable when assigned a value.let and co 4 min read Undefined Vs Null in JavaScript In JavaScript, both undefined and null represent the absence of a meaningful value, but they have different purposes and are used in distinct contexts. Knowing when and how to use each can help you write clearer, more predictable code. Let's see the differences between undefined and null in JavaScri 4 min read How to check for "undefined" value in JavaScript ? In JavaScript, undefined is a primitive value that represents the absence of a value or the uninitialized state of a variable. It's typically used to denote the absence of a meaningful value, such as when a variable has been declared but not assigned a value. It can also indicate the absence of a re 2 min read What does !== undefined mean in JavaScript ? In JavaScript, !== is a strict inequality operator, and undefined is a special value representing the absence of a value or the lack of an assigned value to a variable. The !== operator checks for both value and type equality, and !== undefined is used to verify if a variable is not equal to the und 1 min read How to Replace a value if null or undefined in JavaScript? In JavaScript, replacing a value if it is null or undefined involves providing a default value to use when the original value is either null or undefined. This ensures the application has valid data, preventing potential errors or unexpected behavior. Here we have some common approaches: Table of Co 2 min read Like