JavaScript technology chapter-js automatically converts the type, automatically converts to a string, js avoids the pit of automatic conversion

Automatic type conversion
When JavaScript tries to manipulate a "wrong" data type, it will automatically convert to the "correct" data type.
And often this kind of implicit conversion may bring many inexplicable problems to the program, and it is difficult for us to find out the cause, so you must pay more attention when writing code.
Insert picture description here
Null is converted to 0
Insert picture description here
Null is converted to "null"
Insert picture description here
1 is converted to "1"
Insert picture description here
"5" is converted to 5

Automatically convert to a string
When you try to output an object or a variable, JavaScript will automatically call the toString() method of the variable : give
Insert picture description here
it a thumbs up if you like it!

Guess you like

Origin blog.csdn.net/qq_38161040/article/details/108134617