Hacker News new | past | comments | ask | show | jobs | submit login

I find Avoid Comparing to true and false a little pedantic and can someone explain how it is "... bad as it's ambiguous"?



I'll put my hand up for that mistake. I think the word I was looking for was "redundant", and not "ambiguous". Following the other concept of prefixing your booleans with "can" "has" and "is", your variable names should be self explanatory.

if (isSelectable === true) { ... }

versus:

if (isSelectable) { ... }

It's a shorthand method, similar to why you would use int++; instead of int = int + 1;


I was just wondering the same thing. Thought there was some magic javascript concept I somehow missed. Glad you answered!

Good article, bookmarked it for reference/a checklist.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: