Differences between undefined and not defined in javascript
This article mainly introduces the differences between undefined and not defined in javascript. For more information, see
The study found that there is a big difference between the two. I don't know what the difference is from English. The results are as follows:
Test OS: ubuntu
Test Browser: chrome
Test Case 1
Console. log ()
Error ReferenceError: a is not defined
Test Case 2
Var
Console. log ()
No error is reported, but the output is undefined.
Test Case 2
Var B = {};
Console. log (B.)
No error is reported, but the output is undefined.
Test Case 3
Function c (){
}
Var d = new c ();
Console. log (d.)
No error is reported, but undefined is displayed.
About typeof
All the above objects used for testing use typeof to return String ("undefined ")
About the or operation |
Var d = a | 3
Error a not defined
Var;
Var d = a | 3
Result: d = 3.
Var c = 22 | 44
C = 22
Var c = false | 33
C = 33
If (x ){
}
Error
Var x
If (x ){
}
If not executed
Summary:
There are two types of undefined in js. Although typeof returns both String ("undefined ")
After the definition, but without any operation or an undefined attribute of an object, it belongs to the undefined that can be computed and can be used as a logical operation.
The second variable is completely undefined and has no background (x. a, although x does not have the attribute, but returns x to the face). The error type cannot be used unless the typeof function is used.
In js, the OR operation does not return the bool value, but returns the value calculated by js for the last condition on both sides. For example, 1 | 2 1 is true, and 2 does not need to be calculated, so 1 | 2 = 1 a | 1 error
Var a; a | 1 = 1;
I have searched the dictionary for translation.
Undefined can be translated into: unclear, that is, I don't know what to do.
Not defined can be translated into undefined