first, the JS data type is divided into 6 kinds, namely null, Undefined, Boolean, string, number, object. Where object is a reference type, the remaining 5 types are basic or are called primitive types.
Type conversion is an implicit conversion! The types are converted before different types of variables are compared. Implicit conversions typically occur when operators add, subtract, multiply, divide, and are greater than, less than, and so on.
The typeof () method is used to print to determine what data type an element is.
1. Conversion of strings and numbers to each other:
(1), string plus number | | Numbers plus strings, numbers = = strings
eg
typeof ("Hello"); = = "string"
typeof (2); = "Number"
typeof ("6"); = = "string"
"Hello" + 2 = "Hello2"
2 + "Hello" = "2hello"
"6" + 2 = "62"
2 + "6" = "26"
(2), number minus string | | string minus number, String = = Number (at this point, the string is a pure number)
Number Minus string | | string minus number, String = = NaN (at this point, the string is not a pure number)
String minus string, String = = Number (at this point, the string is a pure number)
String minus string, String = = Nan (not a purely numeric string converted to Nan)
eg
2-"hello" + = NaN
2-nan = NaN
"Ten"-5 = 5
"Hello"-5 = NaN
"+"-"+" = -
"Hello"-"ten" = NaN
"Hello"-"hello" = = NaN
JS-Implicit conversion