
Undefined vs Not Defined
This is one of the most underrated JavaScript concepts. When I was learning JavaScript, I used to treat errors as noise. Red text → fix somehow → move on. But one error kept showing up again and again: They sound very similar, but they are not . Understanding this one distinction completely changed how I think about JavaScript execution and memory. What undefined actually means undefined is a special keyword in JavaScript. When a variable is created in a JavaScript program, before the code execution a memory is allocated for that variable with undefined . It literally means: “JavaScript knows this variable exists, but no value has been assigned yet.” Example : Output : Why? Because during the creation phase of execution context , JavaScript does this: Sees var x Allocates memory for x Assigns a default value → undefined So when the code runs, x already exists in memory. That’s why undefined is logged in console. undefined is not empty . It has its own memory space. It's a placeholder w
Continue reading on Dev.to JavaScript
Opens in a new tab

