Why is there no comparison statement in this javascript 'If... Else...' statement
conditional-statements, if-statement, javascript
Solution
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`
- `""` (empty string)
- `null`
- `undefined`
- `NaN`
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
Problem
In the following code ``` var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first'); ``` 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. Or is it saying that: if the various $next is equal to $active.next().length then the condition is true?