If bar
is bound to an anonymous function, then it is an object. Objects are 'truthy' in JavaScript.
The only values in JavaScript that are 'falsy' are:
false
null
undefined
''
(empty string)
0
(zero as a number)
NaN
Everything else is 'truthy', including function objects.
If you meant to call the anonymous function, you'd do if (bar(5))
which would call your anonymous function with the argument 5
. Then your anonymous function would return n
(which is 5
in this case). As 5
is not a falsy object, this would go to the true
branch as well. Doing if (bar(0))
would got to the else
branch, because 0
is falsy.