Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
planb
on April 2, 2020
|
parent
|
context
|
favorite
| on:
How to manage HTML DOM with vanilla JavaScript onl...
I had to think for a sec to get this. And this already makes it worse than 3 if statements. Does anyone really find this more readable?
robto
on April 2, 2020
|
next
[–]
Coming from a lisp I often wish other languages had `cond` so I don't have to nest if statements. This looks like a poor man's cond.
So yes, I do find this more readable. It makes it clear that only one branch will get executed.
foldr
on April 2, 2020
|
parent
|
next
[–]
This would be equally clear if the author had just used a sequence of if statements with a 'return' in each one. (Note that Javascript's case has fallthrough, so you can't immediately conclude that only one branch of a case will be executed.)
hombre_fatal
on April 2, 2020
|
parent
|
prev
|
next
[–]
You don't have to nest if-statements and I would say nested-if is wrong. You simply use else-if. It's a flat structure just like cond.
TheRealPomax
on April 2, 2020
|
prev
[–]
you mean two if statements. The last case is a default return.
Consider applying for YC's Summer 2026 batch! Applications are open till May 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: