1. Data type Conversion
parseint () Example:
parseint ("1234blue");//return 1234
parseint ("22.5");//return 22 for integers, the decimal point is an invalid character
parseint ("Blue");//return NaN
Parsefloat () Example:
Parsefloat ("1234blue");//return 1234.0
Parsefloat ("22.34.5");//return 22.34
Parsefloat ("0908");//return 908
Parsefloat ("Blue");//return NaN
Boolean () Example:
Boolean ("");//return false
Boolean ("Hi");//return true
Boolean (+);//return true
Boolean (null);//return false
Boolean (0);//return false
Boolean (New Object ());//return true
Number () Example:
Number (false);//return 0
Number (true);//return 1
Number (undefined);//return NaN
Number (null);//return 0
2. Data validity judgment (e.g. null, empty, etc.)
(1). The NaN property is a special value that represents a non-numeric value, indicating that a value is not a number.
The IsNaN () global function is often used to determine whether a value is a NaN value.
Methods parseint () and parsefloat () return this value when the specified string cannot be resolved.
var exp = number (undefined); Return NaN
if (IsNaN (TMP))
{
Alert ("NaN");
}
(2). Undefined judgment: Use the typeof () method.
var exp = undefined;
if (typeof (exp) = = undefined)
{
Alert ("undefined");
}
(3). Null judgment: Use the typeof () method.
var exp = null;
if (!exp && typeof (exp)! = "undefined")
{
Alert ("is null");
}
JS data type conversion and data validity judgment