Data type Review--JS study note 2015-6-1 (45th day)

Source: Internet
Author: User

First, the data type:

The type of data in JS type can be understood as the tag type in CSS, such as: inline, block, inline-block, table;

Different data types mean that different calculations can be performed, such as number types, which can be subtraction, modulo, self-increasing, self-reducing, etc.

And the string type can seek its length, namely string.length; (Note that string characters are also character-length).

Boolean type, it can be used to judge;

The data types in JS are: Undefined, number, string, Boolean, function, Object

Use typeof to detect data types;

For the object data type, you can add custom properties as long as they are not empty

The array is above the data type Object;json is also the object type;

Null is also the object type;//According to the above means that this is empty objects, is not to add custom attributes;

Second, data type conversion:

In order to realize the calculation or effect we think of (for example, we want to do numerical operations, or to find the length), we need to convert the data type;

Method One:

Number () method--to a numeric type, followed by some rules, (conversion can be converted as far as possible, can not be transferred is Nan)

1 var a = ' +100 ';2 //alert (A+100); ' 100100 '3 //Alert (number (a)); -4 var a1 = ';5 //Alert (number (A1)); 06 var a2 = true;7 //Alert (number (A2)); True-1 false-08 var a3 = [1];9 //Alert (number (A3)); 1 0 It is important to note that when the contents of the array are more, the conversion will also return nan;Ten var a4 = null; One //alert (number (A4)); 0 A  - //var b = ' 200px '; - //Alert (parseint (b)); the  - var c = ' 12.34 yuan '; - //Alert (parsefloat (c)); -  + var num = ' 200.45 '; - if (parseint (num) = = parsefloat (num)) { + alert (num + ' is an integer '); A }else{ at alert (num + ' is fractional '); - } -  - //////////////////////////////////////////////////////////////////////////// -  - var json = {}; in //Alert (number (JSON)); -  to var u; + //Alert (Number (U)); -  the var a3 = function () {alert (1);}; *Alert (number (A3)); NaN

Data type Review--JS study note 2015-6-1 (45th day)

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.