Undefined and not defined in JavaScript

Source: Internet
Author: User

The study found that there is a great difference between the two, I do not know from English, the two are different, the results are as follows


Test Os:ubuntu

Test Browser: Chrome


Test Case 1

Console.log (a)


Error REFERENCEERROR:A is not defined

Test Case 2

var a

Console.log (a)

No error, but output undefined


Test Case 2

var b = {};

Console.log (B.A)

No error, but output undefined


Test Case 3

Function C () {


}

var d = new C ();

Console.log (D.A)

No error, but show undefined


About typeof

All of the above objects used for testing are returned with typeof String ("undefined")


About or Operations | |

var d = a| | 3

Error a not defined

var A;

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 in


Summarize:

JS has two kinds of undefined although use typeof return is a String ("undefined")

after it is defined, but without any action or an undefined attribute of an object, it belongs to the undefined that can be used as a logical operation

the second variable, completely undefined, and without any background (X.A, although X has no a attribute, but gives X face), is an error type that cannot be used unless the TypeOf function


JS or operation, does not return the bool value, but return JS on both sides of the last calculation of the conditions, such as 1| | 2 1 is true, 2 does not need to be calculated, so 1| | 2 = 1 a| | 1 Error

var A; a| | 1 = 1;



I found a dictionary and translated it.

undefined can be translated into: not clear, that is, do not know what to do

and not defined can be translated into undefined











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.