js expressions and operators

 
 <script> 
 
//     var r = 8;
//     var pi = 3.14;
//     var s = pi*r*r;
//     alert("圆的面积为"+s);
//          var i=8,j=6;
//          document.write(i+j);
//          document.write("<br />")
//          document.write(i-j);
//          document.write("<br />")
//          document.write(i*j);
//          document.write("<br />");
//          document.write(i/j);
//          document.write("<br />");
//          document.write(i%j);//取余的时候负号只在前面一个数字有用
//          document.write("<br />");
//          document.write(-i%j);
//          document.write("<br />");
// document.write(-i%-j);
// document.write("<br />");

            
            //the plus sign is special
// var a=12,b="33",c=12;
// document.write(a+b);//At this time + is the connector, which automatically connects a and b together to form a new string
// document.write("<br />");
// document.write("33"+"66");
// document.write("<br />");

            /*js code execution order is executed from left to right, in our plus sign connection expression if we say If there is still a value before encountering the string, the addition calculation can be performed according to the original value,
                            and the automatic conversion will be performed after encountering the string, so the result is that the values ​​12 and 12 are first added and then converted into the string "24" and "king" to connect
             */

// document.write(a+c+"king");
            
            //increment/decrement operator++ --
// var num1 = 1;
// alert(num1++);//The suffix form is executed first and then add or subtract 1
// alert(num1);
//          
// var num2 = 1;
// alert(++num2);//The prefix form adds and subtracts 1 first and then executes
// alert(num2);


// var i = 1;
// var a = i++;
// alert (a);
//The result of the operation is 1. The variable i first assigns the original value 1 to the variable a and then adds 1 by itself
           
            . //The string type does not support self-increment and self-decrease
. // var num1="a";
// alert( ++num1);
// var num2=" ";//but empty strings can be
// alert(++num2);
// alert(--num2);


           //undefined does not support increment/decrement
// var num1 = undefined;
// alert(++num1);
// alert(--num1)

          
          //numeric, boolean, null support auto increment and decrement
          
          
          
          // string concatenator+

// var i = 1, j = 2, z = 3;
// document.write(i + j + z + "<br />");
// document.write(" " + i+ j + z);//Add a space to the front, so that the value is automatically converted into a string, and the whole formula becomes the connection of the string, and there is no value Calculate
// document.write("<br />");
// var a = "1", b = "2", c = "3";
// document.write(a + b + c);
 
          / / += -= *= /= %= 
// var a = 1;
// var b = 2;
// alert( a+= b);//a = a + b
// alert(a);









          // Comparison operators == != === !==
// alert(0 == null);//false
// alert(0 != null);//ture
// alert(0 == false);/ /ture
// alert(0 === null);//false
// alert(0 !== null);//ture
// alert(0 === false);//false
// alert(0 ! == false);//ture
//        
// var a = 1 == "1";//ture
// alert(a);
// a = 1 === "1";//false
// alert(a);
          
// alert(NaN = = NaN);//false NaN is the only value that cannot be compared to itself





          //logical operator && || !
          // requires both expressions to be true for the result to be true

// alert(true && true);/ /true
// alert(true && false);//true
// alert(false && false);//true
// alert(true && false);//true
//// alert(true and true)// In error reporting js, and cannot be used to represent &&, or to represent ||, and not to be used!
//        
// alert(true && true);
// alert(true || true);


          //Logical "!", the effect of negation
// alert(!true);




          //In &&
// var i = 0, j = 1;
// if(i++ && j++ ) //step 2
// {
//        alert("yes");
//        alert(i);
// }else{
//        alert ("no");
//        alert(i);//The return result is 1, indicating that i is added 1 after the end of step 2 instead of adding 1 after the end of the loop
//      
// }
// alert (i);
// alert(j);

          /*
                        The result of the operation is yes, the initial value of the variable i is 1, enter the if loop, i first brings the initial value 0, 0 corresponds to the Boolean value false, that is, the result of the entire judgment statement is also It becomes false, then i is incremented by 1,
                        the second expression j++ is short-circuited and not executed, and then the execution code in the curly braces under else is run.
                        Finally, the values ​​returned by i and j are 1 and 1, respectively. If it is ++i, the whole result is true
          */
           
           //In ||, if the first expression is true, the second expression is short-circuited

// var i = 1, j = 0;
// if(i++ || ++j){
//          alert("yes")
// }else{
//          alert("no")
// }
// alert (i);//2
// alert(j);//0

          /* 
                        The variable i first brings the initial value 1 into the judgment statement, and the boolean value corresponding to 1 is true, which results in the second expression ++j Short circuit, the result of the entire judgment statement is true, the judgment statement is ended, and i is incremented by 1.
                        Then loop into the execution statement and output yes.
                       Finally, the output value of i is 2, and the output value of j is the initial value 0 because it is short-circuited.

          */

</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324524135&siteId=291194637