1. Boolean (value): Converts a value to a Boolean type;
2. Nnumber (value): Converts values to numbers (integer or floating-point);
3. String (value): Converts a value to a string.
Let's look at Boolean (): A string with at least one character in the value to convert, a number other than 0 or object, Boolean () returns True if the value to be converted is "empty string", "number 0", "undefined", "null", Then Boolean () returns FALSE. You can use the following code to test
Copy Code code as follows:
var T1 = Boolean ("");//return False, empty string
var t2 = Boolean ("s");//returns True, Non-empty string
var t3 = Boolean (0);//return false, number 0
var t3 = Boolean (1), T4 = Boolean (-1);//return True, not 0 digits
var T5 = Boolean (null), T6 = Boolean (undefined);//return False
var t7 = Boolean (New object ());//returns True, Object
Let's take a look at number (): Number () is similar to parseint () and parsefloat (), and the difference is that numbers () conversions are the entire value, while parseint () and parsefloat () can only convert the beginning digits. For example: Number ("1.2.3"), Number ("123abc") returns Nan, and parseint ("1.2.3") returns 1, parseint ("123ABC") returns 123, Parsefloat ("1.2.3") Returns 1.2, parsefloat ("123ABC") returns 123. Number () first determines whether the value to be converted is fully converted, and then it is called parseint () or parsefloat (). The following is a list of the results after the value call number ():
Number (false) 0
Number (TRUE) 1
Number (undefined) NaN
Number (NULL) 0
Number ("1.2") 1.2
Number ("12") 12
Number ("1.2.3") NaN
Number (new Object ()) NaN
Number (123) 123
Finally, string (): This is simpler, it can convert all types of data into strings, such as: string (FALSE)---"false", string (1)---"1". It differs from the ToString () method in that it differs from the following:
Copy Code code as follows:
var T1 = null;
var t2 = String (t1);//T2 value "null"
var t3 = t1.tostring ();//There will be an error.
var T4;
var t5 = String (T4);//t5 value "undefined"
var T6 = t4.tostring ();//There will be an error.