js 的其它运算符和优先级

三元运算符:

语法为 exp1? exp2:exp3

判断 exp1是true 和 false  如果true,则返回exp2  ,如果false ,则返回exp3

 1 <script>
 2        if(5>1){
 3            alert("true")
 4        }else{
 5            alert("false")
 6        }
 7     //同理
 8        var  x = 5>1? "true":"false"  //把三元运算符的结果赋值给一个变量
 9        alert(x)
10 </script>

逗号运算符:

逗号用来将多个表达式连接为一个表达式,新表达式的值为最后一个表达式的值,多用在变量声明处

void运算符 :

void运算符用业指明一个表达式无反回结果

1 <script>
2         var a =void(1)
3         alert(a)       //返回undefined
4 </script>

typeof运算符:

typeof运算符用来返回一个字符串,返回的是操作数的数据类型

1 <script>
2     //返回的都是数据类型
3          var x = 123   //=>number
4          x = "king"    //=>string
5          x = true      //=>boolean
6          x = undefined   //=>undefined
7          x = null      //=>object
8          alert(typeof  x)
9 </script>

 

原文地址:https://www.cnblogs.com/Ziksang/p/5185891.html