JavaScript serialization 6-converted to Number and Boolean types, operators

One, undertake serialization 5

1. Matters needing attention

For non-String use parseInt () or parseFloat (), it will be converted to String type before operation.

 

    var s1 = false ; 

    var s2 = parseInt (s1); // Here will be converted to a string false first, and then parse the number 

    console.log (s2);

 

2. Add an operator can also achieve the role of conversion into Number

Adding a + sign will not change the sign of the data

Adding the-sign will change the sign of the data

 

    var s5 = "20rem";

    var s6 = +s5;

    console.log(s6);

    console.log(typeof s6);

​

    var s7 = "700";

    console.log(+s7);

    console.log(-s7);

    console.log(s7-0);

Second, convert to Boolean type

Function Boolean (parameter), the parameter description here:

0 "" (empty string) null undefined NaN will be converted to false, others will be converted to ture

Third, the operator

Operators are also called operators, for example: typeof is an operator, classification:

(1) According to the function: arithmetic operator, bit operator, relational operator, logical operator;

(2) Divided according to the number of operands: monocular operator, binocular operator, trinocular operator

1. Addition

important point:

(1) Any value and character string operation will be converted into a string for operation first.

(2) When a non-Number value is calculated, it will be converted to the Number type before the operation.

(3) Any value and NaN are NaN

 

    var s8 = "jao";

    var s9 = "oty";

    console.log(s8+s9)

    console.log(598+NaN);

    console.log("jsof"+NaN);

 

 

2. Subtraction, multiplication, and division. Compared with addition, in addition to addition, strings and their operations will be first converted to Number type

3. Division

If the divisor is 0, then no error will be reported, the result is infinity, which is often used to take infinity.

4. Remainder

Take the remainder, and the rest is consistent with the subtraction rules.

m% n remainder

(1) n = 0, return NaN; (2) n is a decimal, which is also the normal balance

(2)       

    console.log(45%0);

    console.log(5%2.5);

    console.log(5%2);

    console.log(5%2.4);

 

Fourth, the source code:

D6_1_DataTransformParseAndBoolean.html

address:

https://github.com/ruigege66/JavaScript/blob/master/D6_1_DataTransformParseAndBoolean.html​

2.CSDN:https://blog.csdn.net/weixin_44630050

3. Blog Park: https://www.cnblogs.com/ruigege0000/

4. Welcome to pay attention to WeChat public account: Fourier transform, personal account, only for technical communication, reply "gift pack" in the background to get Java big data learning video pack

 

 

Guess you like

Origin www.cnblogs.com/ruigege0000/p/12757975.html