js基础---赋值运算符

    赋值运算符
        = 
            - 可以将符号右侧的值赋值给左侧变量
            
        +=
            - a += 5 相当于 a = a+5
            - var str = "hello";  str += "world";
            
        -=
            - a -= 5  相当于 a = a-5
            
        *=
            - a *= 5 相当于 a = a*5
            
        /=
            - a /= 5 相当于 a = a/5    
    
        %=
            - a %= 5 相当于 a = a%5    

 

 

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript">
            /*
             * =
             *     可以将符号右侧的值赋值给符号左侧的变量
             * += 
             *     a += 5 等价于 a = a + 5
             * -=
             *     a -= 5 等价于 a = a - 5
             * *=
             *     a *= 5 等价于 a = a * 5
             * /=
             *     a /= 5 等价于 a = a / 5
             * %=
             *     a %= 5 等价于 a = a % 5
             *     
             */
            var a = 10;
            
            //a = a + 5;
            //a += 5;
            
            //a -= 5;
            
            //a *= 5;
            
            // a = a%3;
            a %= 3;
            
            console.log("a = "+a);
            
        </script>
    </head>
    <body>
    </body>
</html>

 

上一篇:2021.10.23(2.0)


下一篇:鸡兔同笼问题