When working with JavaScript, you might run into the terms not defined
and undefined
. While they may sound identical, they represent different situations in JavaScript programming.
In phase one memory allocation, the Js will assign each variable a placeholder known as undefined
.
To understand it better. Undefined
occurs when memory is allocated for a variable but no values have been assigned yet.
If a variable is not even declared in the memory allocation and attempted to access, it is known as not defined
.
console.log(x);
var x = 20;
console.log(x);
console.log(y);
The output of the code will be
undefined
20
Uncaught ReferenceError: y is not defined
key points
not defined !== undefined
Never assign undefined to a variable manually.
So this was all about the Undefined and Not defined. Hope it helped you understand the concept better and make your journey of learning JavaScript better.
Thank you for reading the article 🙏🏻 and if you liked it, do share.
Top comments (0)