JScript是否提供三元运算符? [英] Does JScript Provide a Ternary Operator?

查看:71
本文介绍了JScript是否提供三元运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jscript(相对于JavaScript)中是否有三元运算符?如果是这样,语法是什么?

Do we have a ternary operator in Jscript (as opposed to JavaScript)? If so, what is the syntax?

推荐答案

expression ? expression : expression

就像C一样。实际上,这有点宽松,因为JavaScript不是强类型的。因此,运算符的两个可能的分叉可以导致不同类型的值。

just like C. It's a little looser, actually, because JavaScript is not strongly-typed. Thus the two possible "forks" of the operator can result in different types of values.

因此:

alert(document.all ? "Hello from IE!" : "Hello from a non-IE browser!");

大多数情况下,Microsoft的ECMAScript与其他浏览器(或其他服务器-端环境)并不是真的那么好,对于普通的非DOM代码,很少要处理这样的事情。

Most of the time, the differences between Microsoft's ECMAScript and those found in other browsers (or other server-side environments) aren't really that great, and for ordinary non-DOM code it's pretty rare to have to deal with such things.

这篇关于JScript是否提供三元运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆