JavaScript data types are divided into six types, namelynull
,undefined
,boolean
,string
,number
,object
。object
It is a reference type, and the other five are basic types or primitive types.
For example,Number()
,stillparseInt()
、parseFloat()
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) // Ask for rest Output
Type conversion of “++” and “–”
var c = '10'; c++; alert(c); // Output 11 var d = '10'; d--; alert(d); // Output 9
Comparison operator type conversion
alert('10' > 9) // Output truealert('10' > '9') // Output false
Conversion of equal sign operator
alert('10' == 10) // Output truealert('10' == '10') // Output true
Conversion 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) // OutputNaN
The 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.