One: number<===>string conversions between numeric types and string types
There are three ways to number===>string a number to a string:
1. After the number + "";
2. The wrapper type string (number).
3. The toString () method in the prototype prototype of type object;
var num=10; var str1=num+ ""; var str2=String (num); var str3=num.tostring (); typeof (str1) + "<br/>"); typeof (str2) + "<br/>"); typeof
Output:
10string10string10string
Here are a few of the few things you need to know: toFixed (number of decimal places);
Toexponential ()//index indication;
Toprecision ()//number of significant digits;
String===>number String type to numeric type
1. Multiply the string by 1;
2. Reduce the string by 0;
3. The type of packaging using the numeric type number (str);
4.parseInt (str)/parsefloat (str);
varStr= "10"; varN1=str*1; varn2=str-0; varn3=Number (str); varn4=parseint (str); varn5=parsefloat (str); document.write (N1+ " " +typeof(N1) + "<br/>"); document.write (N2+ " " +typeof(n2) + "<br/>"); document.write (N3+ " " +typeof(n3) + "<br/>"); document.write (N4+ " " +typeof(N4) + "<br/>"); document.write (N5+ " " +typeof(N5) + "<br/>");
Results:
Number Ten number number ten number
Two: Boolean<===>number,string Boolean type and number type, mutual transfer between string types
Number===>boolean conversion of numeric types to Boolean types
1. Non-zero is true, 0 is false----implicit conversion
2.Boolean (number)----Display conversion
3.!! Number--Take the inverse two times
String===>boolean String type conversion to Boolean type
1. Non-empty strings are true, empty strings are false (spaces are not empty strings)----implicit conversions
2.Boolean (String)----display Conversion
3.!! String--Take the inverse two times
Boolean===>number Boolean type to numeric type
Number (Boolean) true corresponds to 1; False corresponds to 0.
Boolean===>string Boolean type to String type
String (Boolean) true corresponds to true; False corresponds to False.
Any non-empty objects (object) are true. Null,undefined is true.
Three: | | and && has another purpose besides doing logical operations
* In | | If the object is placed on both sides, first determine whether the left object is true, if the left object is returned, otherwise the right object is returned, if the right object is also true, returns undefined.
* On both sides of && If the object is placed, first determine whether the left object is false, if the left object is returned, otherwise the right object, if the right object is also false, return undefied.
The interaction between JavaScript three data types