The keyword “undefined” indicates that the accessed variable is declared in the program; however, we have not assigned any value to it.
As no value is assigned to the variable “emp_name”, the program will print “undefined” on the console
Now, we will assign the value “John” to the variable “emp_name” and try to display the specified value as output:
Hence “emp_name” is no longer “undefined”, so the “console.log()” method will print “John” as its value:
Now, let’s move ahead to know about the “not defined” keyword.
The keyword “not defined” indicates that the accessed variable does not exist in the memory. So, when we access a variable that is not declared in the program, it will print “not defined” on the console.
For instance, in the following example, we will access the variable “emp_age” that is not declared in the program:
The program will print “not defined” on the console: