运算符(算数、比较、逻辑)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- 算数运算符
+ - * / %-->
</body>
<script>
    console.log(2 + 3);//5
    console.log("2" + 3);//23
    console.log(2 + true);//3
    console.log("2" + true);//2true
    console.log(2 + null); //2
    console.log(2 + undefined);//NaN(Not a Number) 非数字
    console.log("2" + undefined);//2undefined  

    // 1.当加号两侧同时为数字,加法运算
    // 2.当加号任何一侧有字符串,字符串拼接
    var a = 10, b = "hello";
    console.log(a + b);//10hello
    // 1.当加号两侧同时为数字,加法运算
    // 2.当加号任何一侧有字符串,字符串拼接

    // +
    console.log(2 + 4);//6
    console.log(2 + 4 + "=");//6=
    console.log(2 + 4 + "=" + 3 + 3);//6=33
    console.log(2 + 4 + "=" + (3 + 3));//6=6

    // -
    console.log(2 - 1);//1
    console.log(2 - 3);//-1
    console.log(2 - false);//2
    console.log(23 - "3");//20
    console.log("23" - "3");//20
    console.log(2 - null);//2
    console.log(2 - undefined);//NaN
    console.log(2 - "abc");//NaNr

    //*
    console.log(2 * 1);//2
    console.log(2 * 3);//3
    console.log(2 * false);//0
    console.log(23 * "3");//69
    console.log("23" * "3");//69
    console.log(2 * null);//0
    console.log(2 * undefined);//NaN
    console.log(2 * "abc");//NaN

    //a+=1;
    //a++;  //a+=1  a = a + 1
    // ++a;
    // console.1og(a);
    var a = 10;
    console.log(a);//10
    console.log(a++);//10
    console.log(a);//11
    var b = 10;
    console.log(b);//10
    console.log(++b);//11
    console.log(b);//11

    // 取余
    // console.log(10 % 2);//0
    console.log(10 % 3);//1
    // 1.当加号两侧同时为数字,加法运算
    // 2.当加号任何一侧有字符串,字符串拼接
//     一元运算符:一个运算符,一个运算子 a++ ++a
//     二元运算符:一个运算符,二个运算子 a+b a +=10

</script>


</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值