What is the Difference between Undefined and Notdefined- vsdifference

The term Undefined basically means memory is declared for a variable or there is a place in memory for that variable. On the other hand, Not defined means there is no memory allocated for variables. 

Let’s understand this in detail. 

If you are programming in Javascript then you may have come across statements like the variable is undefined or the variable is not defined. But how are they different from each other? In this post, we will see what is the difference between Undefined and not defined in Javascript in detail. 

Undefined vs Not defined: What is the meaning of these words?

Undefined in Javascript:

Before we dig deeper, the first question is What is undefined in Javascript?

Undefined is a very essential and basic keyword in Javascript. When you declare a variable and you don’t assign value to it then Javascript will assign a memory space or placeholder to that variable in memory. 

In other words, we can say a place for a variable to store a value. 

var=a; 

In this code, we just declared a without storing a value in it so the browser will set it as an undefined value. 

Like in the above’s Image the variable a is declared without value then the browser indicated that the value is undefined. 

How to Check Undefined Variables in Memory?

To Understand the Underfined vs Not defined, you need to understand How Javascript Program is Executed? When you run Javascript Program the Global execution context is made. The Javascript program executes in a two-step, the first step is the memory allocation phase, and the second step is the value assign phase. 

Let’s understand this by a Program…

console.log(a);
Var a = 5;
Var b =7;
console.log(b);

In this Program what do you think might be the output? 

The output will be:

Undefined
7

As I said in the first step it allocated the memory to a variable and in the second step it just assigned the value and that’s why we saw console.log=undefind because a is defined after that line. 

So our main question was, How we can check variables in memory in Javascript?


When you open the console in Browser you will see in the console in Global execution content the memory will be declared and that will be undefined. Check the Image below. 

Not Defined in Javascript?

Not Defined is easy, if you do not declare a variable and try to access it will show you the variable is not defined. 

Not defined in Javascript basically stands for a variable that does not exist in memory. No placeholder in memory of that memory.

Supposed this is your program:

car b=5;
Var c =7;

console.log(a);

In the above program, we declared the b and c variable and trying to call a, as it is not defined Javascript gonna throw a not defined error just like we can see in an Image below

Difference between Undefined and Not defined in Javascript: Table

UndefinedNot Defined
If we declare the variable and don’t assign value in it then it will be Undefined When we don’t declare a variable and try to access it then Javascript will show it as a variable is not defined
There will be place in memory of Undefined No place in memory 
It is a special Keyword in JavascriptIt is the error basically

Also Check: Difference Between NPM and NPX in Flutter

Conclusion:

So we can say both Undefined and Not defined both are memory related. Undefined is basically a keyword, a variable without a value is undefined. it while Not defined is an error that javascript throws when it can’t find the variable in memory. 

Leave a Reply

Your email address will not be published. Required fields are marked *