Study Notes on JavaScript advanced programming (1): Some weird features of JavaScript Data Types

Source: Internet
Author: User

Learning. Some strange features of JavaScript data types are found:

Javascript is a very flexible scripting language. In addition to the well-known weak types and weak definitions, there are also some weird features that are not quite relevant to JavaScript data types:

1. The string type in Javascript is the original type, that is, it is placed in the stack rather than in the heap, which is different from other languages.

2. null and undefine, although JavaScript defines them as equal, alert (null = undefined) try!
However, they have different meanings. undefined declares variables but never initializes or assigns values to them. Null indicates that it does not exist. If a function or method returns an object, null is returned if the object cannot be found.

3. null is also an object. It is considered a placeholder for an object. Alert (typeof null) try it!

4. Nan (not a number), indicating a non-number. However, its uniqueness is that it is not equal to itself. Alert (Nan = Nan), returns false. Therefore, we generally do not recommend using the Nan value itself, but using isnan () for determination.

5. Generally, double quotation marks (") are used to represent strings and single quotation marks (") are used to represent characters. JavaScript does not matter, so the following are the same.
VaR Ss = "blue"; var Ss = 'blue ';

6. javascrip all objects have the tostring () method, whether it is an object or a pseudo object. Because the string type is a pseudo object, there must be the tostring () method (except null)
Alert (document. tostring () try!
In fact, there are also ways to convert null to a string: forced conversion (smug)
VaR S1 = string (null );
Alert (S1 );

 

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.