What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?
Interviews2 answers
What's the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?
2 Answers
null is a value of a variable and is a type of object. We use ‘console. log();’ and ‘type of’ to check if a variable is undefined or null. undeclared variables is a variable that has been declared without ‘var’ keyword.
Rajeev KumarPosted Mar 9, 2023, 8:45 AM EST
Null is absence of memory for particular variable.
e.g var a = null;
undefined indicate value has not been assign to it.
e.g var x; // x is undefined
Undeclared means variable is not declared with any data type.
suraj devgadePosted Mar 27, 2022, 4:47 AM EDT


