Let's first clarify the distinction between a declaration and a definition before moving on to more detailed discussion.
The fact that we are announcing the existence of a variable and the necessity for memory allocation makes the variable x a declaration even though its value has not yet been determined.
var x; // declaring x console.log(x); // output: undefined
An undefined variable can be declared. When we attempt to access it, the outcome will be undefinable.
var x; // Declaration typeof x === 'undefined'; // Will return true
A variable cannot be defined or declared. The result will be not defined?if we attempt to reference such a variable.
console.log(y); // Output: Reference Error: y is not defined
Difference between undefined and not defined
|It functions similarly to when a variable is declared in code but not assigned a value before being printed.||It functions similarly to when we try to call a variable even though we haven't declared it.|