JavaScript data types

Source: Internet
Author: User

Points:

1 , typeof operator

var box=false;alert (typeof Box);

2 , Undefined type

var box;//undefined type alert (box)

3 , Null type

Alert (undefined==null)//undefined are derived from null, so they are two equal and return True

4 , Boolean type

var box =true//true is not necessarily the 1,false is not necessarily 0.javascript case-sensitive, true is not a Boolean value of alert (typeof box)

to convert a value to its corresponding Boolean value, you can use the conversion function Boolean () , which is an explicit conversion, is mandatory.

var he = ' Hehh ' var he2 = Boolean (He) alert (typeof He2)

5 , Number type

var box = 250;//decimal integer alert (box); var box =070;//octal integer, decimal output 56alert (box); var box = 3.80;//Floating-point alert (box); var box = 12.0;//automatically converts alert (box); var box = 4.12e3;//Science and Technology Act alert (box); var box =0.000000000412;//Science and Technology Act alert (box); var box =100e10000;//over range alert (box); var box = 100e10000;alert (isfinite box),//isfinite function checks for out-of-range, returns false or true/*nan, that is, non-numeric (not anumber) is a special value, This value represents a case where the operand that would have returned a numeric value did not return a value (so that no error was made). *///var box = 0/0;//nan//alert (Number.NaN)//Number.NaN Get NaN value//alert (nan+1)//any operation with Nan results in Nan//alert (Nan ==nan) Nan is not equal to itself (Nan is not equal to any value) the/*isnan () function is used to determine whether the value is Nan. The IsNaN function receives a value and attempts to convert it to a numeric value *///alert (IsNaN (NaN))//true//alert (IsNaN)//false/* There are 3 functions converting a non-numeric value to a value: Number (), parseint () and parsefloat (). Number () applies to any type, and the latter two is dedicated to converting a string to a numeric value. *///alert (number (true)); True and false//1,boolean types are converted to 1 and 0//alert respectively (numbers (25));//25, Numeric returns directly//alert (# (NULL)) ;//0, empty object returns 0//alert (number (undefined)),//nan,undefined returns Nan//alert (parseint (' 456lee '));//456 returns the integer part//alert ( parseint (' Lee456lee '))//nan, the first one that is not a value returns Nan//alert (parseint (' 12lee34lee ')//12, starting with the first value, to the last continuous numeric//alert (parseint (' 12.34 '))//12, the decimal point is not a value, remove the//alert (parseint ("))//nan, The null return Nanparsefloat () is used for floating-point numeric conversions, as is the case with parseint (), which, from the first to the non-floating-point numeric position, recognizes only a small number of decimal points and converts the scientific notation to a normal value.

6 , String type

String type some escape characters .

var box = 11;var box = True;alert (typeofbox.tostring ()); the//string,tostring () method converts the value to a string. The/*tostring () method generally does not need to be passed, but when the value is converted to a string, it can be passed the */var box = 10;alert (box.tostring ());//10, the default decimal output alert (box.tostring (2)); /1010, binary output

7 , Object type

You can also use New operator to create other types of objects. (newstring(' Xu '),new Boolean (True))

JavaScript data types

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.