This article describes the use of undefined variables or values in JavaScript. Share it for your reference, as follows:
Undefined values cannot be used in JavaScript, except for the following situations:
1. In the assignment statement:
a=9;alert(a) //9
The variables that need to be assigned in the assignment statement will be defined first and then assigned. In addition, from a=b=c=8 without reporting an error, it can be seen that the assignment statement is executed from right to left.
2. In the for in statement:
for(key in {name:'goofy'}){ alert(key) //"name"}alert(key) //"name"If the variable on the left of in statement is not defined, it will be defined first
3. After the typeof operator:
alert(typeof a) //'undefined'alert(a) //Uncaught ReferenceError: a is not defined
The typeof operator can be associated with an undefined value, but it will not be defined actively.
4. Object properties:
var o={name:'goofy'}alert(o.name) // 'goofy'o[age]=24; // Uncaught ReferenceError: age is not definedalert(o.age)When defining object properties, if it is a json direct quantity form, you can use undefined values, but if you use the subscript form, you will report an error
5. Function parameters:
function fn(a,b){ alert(a) //4 alert(b) //'undefined'}fn(4)The parameters will be automatically defined when the function is executed, so the function parameters can be used directly in the function body. This parameter is not passed or errors will be reported when the instant method is called.
For more information about JavaScript related content, please check out the topics of this site: "Summary of JSON operation skills in JavaScript", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation special effects and techniques", "Summary of JavaScript errors and debugging skills", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques" and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.