Difference between undefined and undeclared variables.
Interview question and answer by:
Ddd | Posted on: 2/21/2011 | Category:
JavaScript Interview questions | Views: 3236 | |
Points: 40
Answer:
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 .
example:
<script>
//a is undefined variable
var a;
alert(a);
//b is undeclared variable
alert("hello"+"--"+b);
</script>
a:undefined:
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
Found interesting? Add this to: