Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"if" helper considers 0 to be a falsy value #597

Closed
artiee opened this issue Aug 13, 2013 · 3 comments
Closed

"if" helper considers 0 to be a falsy value #597

artiee opened this issue Aug 13, 2013 · 3 comments

Comments

@artiee
Copy link
Contributor

artiee commented Aug 13, 2013

The if-helper seems to consider value 0 (zero) to be falsy because the simple "!conditional" -test is used. This creates problems with many apps as 0 should be considered as a real value. The falsy values should be 'undefined', null, false, '', [], and {}.

Also the Utils.isEmpty seems to recheck that value isn't 0. This seems unnecessary.

@gnclmorais
Copy link

If this gets accepted, can you please add this behaviour to the documentation (i.e. write that 0 is not a falsy value)? I ask this because, as a JavaScript developer, I would kind of expect 0 to be evaluated as falsy... And thus it would be clearer for everybody. Thank you.

artiee added a commit to artiee/handlebars.js that referenced this issue Aug 15, 2013
@kpdecker
Copy link
Collaborator

@artiee @gnclmorais See #608 for discussion on this. After checking the new behavior for the upcoming alpha release I am worried that this will break almost all code that is out there already and the expectations of javascript developers as @gnclmorais notes.

@kpdecker
Copy link
Collaborator

kpdecker commented Nov 4, 2013

Released in 1.1.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants