Differences between undefined and notdefined in javascript _ javascript skills

Source: Internet
Author: User
This article mainly introduces the differences between undefined and notdefined in javascript. If you need it, you can refer to the study and find that there is a big difference between the two, the differences between the two 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.