zoukankan      html  css  js  c++  java
  • Js 运算符(加减乘除)

    1.加法

    复制代码
    var box=1+2                       //3
    var box=1+NaN                     //NaN,有一个为NaN就为NaN
    var box=Infinity+Infinity      //Infinity
    var box=-Infinity + -Infinity    //-Infinity
    var box=Infinity + -Infinity     //NaN,正无穷和负无穷相加为NaN
    var box=100+ '100';            //100100,有一个为字符串相加为字符串拼接
    var box='你的年龄是'+10+20;       //你的年龄是1020,后面的整形已转换成字符串
    var box='你的年龄是'+(10+20);     //你的年龄是30,后面的整形先相加在转换吃字符串
    var box=10+20+'是你的年龄';       //30是你的年龄,先相加,在转换成字符串
    var box=10+对象;              //10[object Object],如果有toString()或valueOf()则返回10+返回的值
    复制代码

    注:++和--一样

    var box=1;
    box++;         //box=2,box=box+1
    ++box;         //box=3,box=box+1
    var age=box++  //box=4;age=3,先赋值在运算
    var pox=++box  //pox=5;box=5,先运算在赋值

    2.减法

    复制代码
    var box=100-70;  //30
    var box=-100-70; //-170
    var box=-100--70; //-30
    var box=-100-NaN   //NaN
    var box=Infinity-Infinity   //NaN
    var box=-Infinity--Infinity //NaN
    var box=Infinity--Infinity //Infinity
    var box=-Infinity-Infinity //-Infinity
    var box=100-true;     //99,true转换成数值为1
    var box=100-'';      //100,''转换为0
    复制代码

    3.除法

    复制代码
    var box=100/70   ///1.42....
    var box=100/NaN   ///NaN
    var box=Infinity/Infinity  ///NaN
    var box=-Infinity/Infinity  ///NaN
    var box=-Infinity/-Infinity  ///NaN
    var box=100/true       ///100,true转换成1
    var box=100/''          /// Infinity
    var box=100/null         ///Infinity
    var box=100/'lee'         ///NaN
    var box=100/对象            ///NaN ,如果有toString()或valueOf(),返回10/返回值
    复制代码

    4.求模

    var box=10%3;     //1,余数为1
    var box=100%NaN;  //NaN
    var box=Infinity%Infinity  //NaN
    var box=100%true        //0
    var box=100%''          //NaN
    var box=100%null        //NaN

    原文:https://www.cnblogs.com/xiaoxinzi/p/8482836.html

  • 相关阅读:
    20180710
    20180709
    20180706
    20180705
    20180704
    python3.x 函数的参数
    python函数返回值
    Centos7下命令笔记-ls
    CentOS系统内核、操作系统位数以及系统参数查看
    CentOS7 配置光盘iso镜像为本地yum源
  • 原文地址:https://www.cnblogs.com/zhang1f/p/13535054.html
Copyright © 2011-2022 走看看