Difference between undefined and undeclared variables.

 Posted by Ddd on 2/21/2011 | Category: JavaScript Interview questions | Views: 8766 | Points: 40

undefined variables are those that are not assigned any value but declared in the program.
if we try to read the value, an error message "undefined" is displayed.

undeclared variables are those that are not declared in the program .
if we try to read their values gives runtime error.
But if undeclared variables are assigned some value then implicit declaration is done .

//a is undefined variable
var a;
//b is undeclared variable


b:will also be undefined but that error message can be seen by clicking in browser
status bar: if some value is assigned to b, then it will be displayed in the output

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response