Page 65 - JavaScript
P. 65

false + 5;        // 5
         null + 1;         // 1
         undefined + 1;    // NaN


        If a boolean value is given alongside a string value, the boolean value is converted to a string
        instead:


         true + "1";        // "true1"
         false + "bar";     // "falsebar"


        Subtraction (-)


        The subtraction operator (-) subtracts numbers.




         var a = 9;
         var b = 3;
         var c = a - b;


        c will now be 6

        If a string or boolean is provided in place of a number value, it gets converted to a number before
        the difference is calculated (0 for false, 1 for true):


         "5" - 1;     // 4
         7 - "3";     // 4
         "5" - true;  // 4


        If the string value cannot be converted into a Number, the result will be NaN:


         "foo" - 1;      // NaN
         100 - "bar";    // NaN


        Multiplication (*)


        The multiplication operator (*) perform arithmetic multiplication on numbers (literals or variables).


         console.log( 3 *  5); //  15
         console.log(-3 *  5); // -15
         console.log( 3 * -5); // -15
         console.log(-3 * -5); //  15



        Division (/)


        The division operator (/) perform arithmetic division on numbers (literals or variables).


         console.log(15 / 3); // 5
         console.log(15 / 4); // 3.75






        https://riptutorial.com/                                                                               22
   60   61   62   63   64   65   66   67   68   69   70