zoukankan      html  css  js  c++  java
  • js的运算符学习笔记

    js的运算符

    image


    1、加号运算

    <!DOCTYPE html>
    <html lange = "en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <h1>js运算</h1>
        <h2>加号运算</h2>
        <script type="text/javascript">
            var a = 1 + 1 + "a" + ( 1 + 2 );
            document.write(a);
    
        </script>
    
    
    
    
    </body>

    运行结果为:注意运算顺序

    image

    减号运算和称号运算  略

    除号运算

    <!DOCTYPE html>
    <html lange = "en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <h1>js运算</h1>
        <h2>加号运算</h2>
        <script type="text/javascript">
            var a = 1 + 1 + "a" + ( 1 + 2 );
            document.write(a);
    
        </script>
    
        <h2>除号运算</h2>
        <a>     1/0 是无穷 a = 1 / 0 =
        <script type="text/javascript">
            var a = 1 / 0;
            document.write(a);
    
        </script>
    
        </a>
    
        <br/>
        <a>     0/0 得到的不是数 a = 10 / 0 =
        <script type="text/javascript">
            var a = 0 / 0;
            document.write(a);
        </script>
    
        </a>
    
    </body>


    结果为

    image


    取余运算 %(略)


    ++  --

    <!DOCTYPE html>
    <html lange = "en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <h1>js运算</h1>
        <h2>加号运算</h2>
        <script type="text/javascript">
            var a = 1 + 1 + "a" + ( 1 + 2 );
            document.write(a);
    
        </script>
    
        <h2>除号运算</h2>
        <a>     1/0 是无穷 a = 1 / 0 =
        <script type="text/javascript">
            var a = 1 / 0;
            document.write(a);
    
        </script>
    
        </a>
    
        <br/>
        <a>     0/0 得到的不是数 a = 10 / 0 =
        <script type="text/javascript">
            var a = 0 / 0;
            document.write(a);
        </script>
    
        </a>
    
        <br/>
        <a>      b = a++ 
        <script type="text/javascript">
            var a = 10;
            b = a++
            document.write("a = " + a + " b = " + b);
        </script>
    
        </a>
        <br/>
        <a>     b = ++a    
        <script type="text/javascript">
            var a = 10;
            b = ++a
            document.write("a = "  + a + " b = " + b);
        </script>
    
        </a>
    </body>

    赋值运算  从右向左  ,计算顺序  从左至右

    image


    a+=10  等同于 a+=10

    a += 10 +1 为 a+10

    结果为21

    人在中年,一事无成,瞎学
  • 相关阅读:
    python爬虫模拟登陆
    华为手机怎么连接苹果电脑?
    python 3 爬取百度图片
    让Netty入门变得简单
    ylbtech-LanguageSamples-UserConversions(用户定义的转换)
    ylbtech-LanguageSamples-Unsafe(不安全代码)
    ylbtech-LanguageSamples-Threading(线程处理)
    ylbtech-LanguageSamples-Struct(结构)
    ylbtech-LanguageSamples-SimpleVariance
    ylbtech-LanguageSamples-Security(安全)
  • 原文地址:https://www.cnblogs.com/jilingxf/p/13820567.html
Copyright © 2011-2022 走看看