Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第4题(2019-07-25) 以下代码输出什么? #20

Open
qappleh opened this issue Aug 19, 2019 · 1 comment
Open

第4题(2019-07-25) 以下代码输出什么? #20

qappleh opened this issue Aug 19, 2019 · 1 comment
Labels

Comments

@qappleh
Copy link
Owner

qappleh commented Aug 19, 2019

var a = 1 < 2 < 1 < 1 ? 3 : 4;
var b = 3 < 2 < 1 < 1 ? 2 : 1;
console.log(a);
console.log(b);  
@qappleh
Copy link
Owner Author

qappleh commented Aug 19, 2019

答案:3 1
解析:大于小于运算符优先级高于三目运算符,且从左往右执行 a的执行顺序如下: 第一步:1 < 2 为true 第二步:true < 1,这时true会转为1,false会转为0进行比较,因此这一步结果为false 第三步:fasle < 1,结果为true,因此a的结果是3 b的结果同理于a,不再写详细计算步骤。

@qappleh qappleh added the js label Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant