Automatic data type conversion JavaScript

In JavaScript program stored in the variable data type does not limit
that is variable photographs that can store data of any type of complex JavaScript syntax specification
but in a JavaScript program, often need variable values are stored in a particular data type, now you need to convert the data types of
the so-called data conversion is to convert the current data type to another data type
conversion in JavaScript data types, and automatically converted into mandatory conversion
automatically translate a computer program to automatically complete the conversion, the conversion is not automatic happen at any time, and only in exceptional cases will be automatically converted, vital principle automatically converted
forcibly converted programmers, forced to complete the conversion
automatically converted
automatically converted 1. Boolean
other data types, automatically converted into Boolean type
in when executed if the judge, other data types are automatically converted to boolean
if you only accepts two input values true and false, if the judge will do what to write back, if ultimately will give him into true and false
other types into Boolean principles
into fa lse: 0 '' (the empty string) undefined null NaN //0.0 0.0000 are 0
addition of all other content will be converted to data to true
2. string is automatically converted into
the other type is automatically converted into a string
and then performs the character when the string of splicing, other data types will be converted to a string
Performing string concatenation, should all sides plus the string type, if other types, JavaScript type will be automatically converted to a string, the string true- Boolean 'true', the numerical analysis to the corresponding pure numeric string ( scientific notation, resolved into corresponding values of stitching)
three special conversion:
splicing array: Do [], the data contents of the array into a string splicing operation performed
splicing object (any object will be converted to anything [object, Object])
splice function: function have become the entire string
3. the value of the automatic conversion
of other types of conversion to numerical values: when a mathematical operation, will trigger automatically converted data type
Boolean: true-1; 0-to false;
undefined- into NaN, NaN involved in computing the result was NaN3
NULL-0 is converted to
a string - If the entire string is converted purely scientific notation number string and a corresponding value
If the string does not comply with a number NaN content specification into
an array, object, function: if plus, string mosaic effect is performed
if other forms of The operation, the result is NaN execution

Published 21 original articles · won praise 3 · Views 332

Guess you like

Origin blog.csdn.net/qq_44531034/article/details/104784728