什么:在Javascript中意味着什么? [英] What does ? : mean in Javascript?

查看:168
本文介绍了什么:在Javascript中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这行代码有什么作用?

len = ( s.length>t.length ) ? s.length : t.length


推荐答案

?:是三元运算符。它根据条件返回一个值。

?: is the ternary operator. It returns a value based on a condition.

x = (condition)?(if-true):(if-false)

因此,如果condition为true,则x为if-true部分中的值,如果为false ,那么x是if-false中的值。

So if condition is true, x is the value in the if-true section, and if it's false, then x is the value in if-false.

如果等于Corv1nus之前所说的那样。

If is equivalent to what Corv1nus said earlier.

这篇关于什么:在Javascript中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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