Undefined: It occurs when a variable has been declared but has not been assigned any value. Undefined is not a keyword.
Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using the var or const keyword. If we use ‘typeof’ operator to get the value of an undeclared variable, we will face the runtime error with the return value as “undefined”. The scope of the undeclared variables is always global.
let geek; undefined console.log(geek)
//ReferenceError: myVariable is not defined console.log(myVariable)
Example 1: This example illustrates a situation where an undeclared variable is used.
ReferenceError: x is not defined
Example 2: This example checks whether a given variable is undefined or not.
My Personal Notes arrow_drop_up
Please Login to comment...