Summary: implicit type conversion in Javascript, summary javascript Conversion
JavaScript data types are divided into six types:null
,undefined
,boolean
,string
,number
,object
.object
Is the reference type, and the other five are the basic type or the original type.
For exampleNumber()
, OrparseInt()
,parseFloat()
All belong to the display type conversion (forced type conversion );
In this section, we will look at implicit type conversion (automatic conversion ).
The value is automatically converted to a string.
Var a = 123; alert (a + '20140901'); // output 456
"+" Is the connector
The string is automatically converted to a number.
Var B = 20; // alert (B-'10'); // subtraction output 10 // alert (B * 2 ); // output 40 by multiplication // alert (B/2); // output 10 by Division // alert (B % 2) // return output
Type conversion between "++" and "-"
Var c = '10'; c ++; alert (c); // output 11var d = '10'; d --; alert (d); // output 9
Type conversion of comparison Operators
Alert ('10'> 9) // output truealert ('10'> '9') // output false
Equal sign operator Conversion
Alert ('10' = 10) // output truealert ('10' = '10') // Output true
"!" Operator Conversion
Alert (! True); // outputs falsealert (! 100); // output falsealert (! 'Front-end web'); // outputs false
NaN is returned for conversions between other operators.
Alert ('web front-end developer'-10) // output NaN
The above is all the content of implicit type conversion in Javascript. I hope the content in this article will be helpful for your learning work. If you have any questions, please leave a message.