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)