JavaScript is an untyped language, but at the same time JavaScript provides a flexible way to handle automatic type conversions. The basic rule is that if a value of a type is used in an environment that requires other types of values, JavaScript automatically converts that value to the desired type.
The following is the conversion that is performed when a specific type of JavaScript is used in a particular environment.
Type conversions
Value String Numeric Boolean object
"Undefined" NaN false Error not defined
Null "NULL" 0 false Error
Non-empty string as is the numeric value of the string or the Nan True string object
Empty string as is 0 false string object
0 "0" as is false number object
Nan "Nan" as is false number object
Infinity "Infinity" as is true Number object
Negative Infinity "-infinity" as is true Number object
String value of all other numeric numbers Asis true Number object
True "true" 1 as is Boolean object
False "false" 0 as is Boolean object
Object ToString () valueOf () or ToString () or Nan true as is
Type conversions like JavaScript