为什么在这个javascript'If ... Else ...'语句中没有比较语句 [英] Why is there no comparison statement in this javascript 'If... Else...' statement

查看:111
本文介绍了为什么在这个javascript'If ... Else ...'语句中没有比较语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中

var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

零件'$ active.next()。length'似乎没有比较任何东西我不明白条件如何被判定为真或假。

the part '$active.next().length' doesn't seem to compare anything and I don't understand how the condition is determined to be True or False.

或者是说:
如果各种$ next等于$ active.next()。length那么条件是真的吗?

Or is it saying that: if the various $next is equal to $active.next().length then the condition is true?

推荐答案

在javascript中,任何表达式都可以转换为truthy或falsy值,因此在比较位置有效。 javascript中为false的值为

In javascript any expression can be converted to a truthy or falsy value and hence is valid in a comparison place. The values which are false in javascript are


  • false

  • 0

  • (空字符串)

  • null

  • undefined

  • NaN

  • false
  • 0
  • "" (empty string)
  • null
  • undefined
  • NaN

在这种情况下 length 是指一个数值,如果它的计算结果为 0 ,那么它将被视为假。否则它将是真实的

In this case length refers to a numeric value and if it evaluates to 0 then it will be considered falsy. Otherwise it will be truthy

这篇关于为什么在这个javascript'If ... Else ...'语句中没有比较语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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