JavaScript data types are divided into six types, namely null , undefined , boolean , string , number , object . object is a reference type, and the other five are basic types or primitive types.
For example, if it is Number() , parseInt() , and parseFloat() , they all belong to display type conversion (cast type conversion);
In this section, we will take a look at implicit type conversion (automatic conversion).
Automatically convert numeric values to strings
var a = 123;alert(a+'456'); // Output 123456
"+" sign is the connection character
Automatically convert strings to numbers
var b = 20;//alert(b-'10'); // Subtraction output 10//alert(b*2); // Multiplication output 40//alert(b/2); // Division output 10//alert(b%2) // Find the remaining output
Type conversion of "++" and ""
var c = '10';c++;alert(c); // Output 11var d = '10';d--;alert(d); // Output 9
Comparison operator type conversion
alert('10' > 9) // Output truealert('10' > '9') // Output falseConversion of equal sign operator
alert('10' == 10) // Output truealert('10' == '10') // Output trueConversion of the "!" operator
alert(!true); // Output falsealert(!100); // Output falsealert(!'Web front-end development'); // Output false
Conversion between operators and other conversions return NaN
alert('Web front-end development'-10) // Output NaNThe above is all the content of implicit type conversion in Javascript. I hope the content of this article will be helpful to everyone's study and work. If you have any questions, you can leave a message to communicate.