JavaScript notes Java basic data type < 0 >

Source: Internet
Author: User

 

. Record what you didn't know before.

The
variables explain Example
string String, a section of text. To indicate that variables are strings, you should wrap them in quotation marks. var myvariable = ' Bob ';
number number, one number. Surround it without quotes. is a single data type, internally represented as a 64-bit floating-point number
, as with a double in Java. Nan is a special value. It is not equal to its own.
var myvariable = ten;
boolean Boolean, a True/false (True/False) value. &NBSP true / false   is a special keyword in JS that does not require quotation marks. var myvariable = true;
array Array, a structure that allows you to store multiple values in a reference. var myvariable = [1, ' Bob ', ' Steve ', ten];
The elements of the array are called only:   myvariable[0] , myvariable[1] , and so on.
object object, basically everything in JavaScript is an object, and can be stored in a variable. Keep this in mind. var myvariable = document.queryselector (' H1 ');
All of the above examples are objects.
Undefined is a special class, typeof (undefined) output is defined

Null is summed up as a special class in the list, but the typeof (null) output is an object, how to determine whether it is null, the decision variable temp, see the following code:

[JavaScript]View Plaincopy
    1. if (temp&&typeof (temp) = = ="Object") {
    2. Temp is an array or an object
    3. }


So how to tell if a passed in parameter is an array, the TypeOf operator cannot judge an object or an array, and we need to determine his constructor, see the following code:

[JavaScript]View Plaincopy
    1. if (temp&&typeof (temp) = = =' object ' &&temp.constructor===array) {
    2. //temp is an array
    3. }
The above test will give false when the array is detected in a different frame or window, and the following detection may be more effective when the array is likely to be created in another frame.

[JavaScript]View Plaincopy
    1. if (temp&&typeof (temp) = = =' object ' &&typeof (temp.length) = = =' number ' &&! Temp.propertyenumerable (' length ')) {
    2. }
The arguments array is not an array, it is an object with a length member element. The above detection will recognize the arguments array as an array, which is sometimes the result you want, although arguments does not contain an array method. Anyway, If the Propertyiseumarable method is overwritten, the detection may still fail.

Excerpt from JavaScript essence and MDN

JavaScript notes Java basic data type < 0 >

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.