JavaScript is a weakly typed language that does not enforce its data type when declaring a variable, and automatically transforms the data type according to the context environment.
1) String value converted to numeric
The number function parseint function (can accept the second argument, specify the binary of the conversion, the default decimal) parsefloat function
var a = number (' 100 ');
alert (a);//100
Alert (typeof (a));//number
var B = parseint (' 100 ');
alert (b);//100
Alert (typeof (b));//number
The above two examples all replace the string value with a value
Implicit conversions of string conversions to numeric values
Alert (typeof (' 1 '));//number
Alert (typeof (' + '));//number
In the subtraction operator, the string value is converted to the value by default
When it comes to addition
var str = ' abc ' + 1;
alert (str); ' ABC1 '
Alert (typeof (str));//string
Converts a value into a string value, a connection to a string
2) value converted to string
Call the string function or the ToString method
var a = String (100);
Alert (typeof (a));//string
var B = (+). toString ();
Alert (typeof (b));//string
Implicit conversions of numeric conversions to strings
When it comes to addition
var str = ' abc ' + 1;
alert (str); ' ABC1 '
Alert (typeof (str));//string
Customary methods
Convert string value to numeric
var a = ' 1 ';
Alert (typeof (+a));//number
numeric conversions to String values
var b = 1 + ";
Alert (typeof (b));//string
3) Convert other types to Boolean types
Value 0 value nan null value undefined value null string ' This 5 value will be converted to false when implicit conversion other values are converted to true
if (0) {
}
We can use!! For implicit data-type conversions
! is a Boolean operation of the logical non-operator, you can convert the operand to a Boolean type if it is not a Boolean, so pass!! You can complete the conversion of the Boolean type
JS Data type Conversion