What is the difference between not defined and undefined in javascript?

Source: Internet
Author: User

A conceptual explanation:
undefined is one of the five original classes defined in the JavaScript language, in other words, undefined is not a program error, but a value allowed by the program.
not defined is a bug that JavaScript bursts when it runs our JavaScript code and encounters a variable that is not defined for operation.
So here's the problem: in many JavaScript tutorials, javascript variables are introduced, even if they are not defined, and can be used directly, but be aware that this use refers to the ability to be assigned, but not to be evaluated. See an example

var temp;
TEMP2 = 123;
alert (TEMP2);
Temp3 = temp4+1;
alert (Temp3);

In the above code, the first alert can have a normal pop-up window of 123, but the second alert will not be executed because it is not allowed to use an undefined temp4 to operate.
let's look at an example:

var temp;
alert (temp);
alert (typeof temp);
alert (typeof temp2);
alert (temp==undefined);
alert (temp2==undefined);

in this example:
The first, second, and third alert can pop up the hint undefined, but in fact the meaning of these three undefined is not the same. In JavaScript, undefined is a class, the class has only one value is undefined, the first alert pops up is the value undefined, the second and the third pop up is undefined the class name.
A fourth alert will pop up true, which is a judgment.
The fifth alert will not pop up because of an error. The error here is that the operation is performed using a variable that is not defined. The error that was TEMP2 was not defined; (different browsers may say differently)

What is the difference between not defined and undefined in javascript?

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.