Let us understand it with the help of simple code snippets where we get the value as undefined.
In the third example, we are calling a function multiply which doesn’t have anything to be done inside its body so the output is undefined.
In the fourth and fifth examples, we are trying to access the value of an array and object which is yet not assigned with the value so the output is undefined.
In the above example, we are trying to log the value of the variable c which is yet not defined in this program. This is the reason why this program throws an error ReferenceError: c is not defined.
Now let’s try to see another example with a slight variation. In this example will assign the value to the variable inside the function block and we will get not defined error for that.
In the above example, we can get the error that the value is not defined. This is because we didn’t define it as a datatype of let, const, and var. So the variable ‘value’ doesn’t have a space in the memory and we cannot assign a value to the variable.
This error can easily be solved by using declaring value with let. Hence through this, we give the value variable space in the memory to be able to assign values.