我是靠谱客的博主 义气丝袜,这篇文章主要介绍4.运算符的优先级,现在分享给大家,希望可以做个参考。

4.运算符的优先级

var val = 'smtg';
console.log('Value is ' + (val === 'smtg') ? 'Something' : 'Nothing');  //Something

这个题最容易犯的错误是‘Value is Something’
判断优先级最高的是括号内部的

var val = 'smtg';
console.log('Value is ' + (val === 'smtg') ? 'Something' : 'Nothing');  //Something
//判断优先级最高的是括号内部的
'Value is ' + (val === 'smtg') ? 'Something' : 'Nothing' 
=>等价于'Value is ' + true? 'Something' : 'Nothing' 
//+的优先级高于?的
'Value is ' + true? 'Something' : 'Nothing' 
=> 'Value is true' ? 'Something' : 'Nothing' 
//因为'Value is true' != null,其布尔值为true
'Value is true' ? 'Something' : 'Nothing'  //Something

//综上所述
'Value is ' + (val === 'smtg') ? 'Something' : 'Nothing' //Something

最后

以上就是义气丝袜最近收集整理的关于4.运算符的优先级的全部内容,更多相关4.运算符内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(126)

评论列表共有 0 条评论

立即
投稿
返回
顶部