Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
z3t4
on April 25, 2018
|
parent
|
context
|
favorite
| on:
JavaScript Pattern Matching Proposal
Stop using (nested) ternary operator's ! Use if-statements!
if(val==1) var res = 1; if(val==2) var res = 2;
Epenthesis
on April 25, 2018
|
next
[–]
Except ternary expressions have the
huge
advantage that they allow assigning to
const
. Eg:
const var = val == 1 ? 1 : va1 == 2 ? 2 : null;
z3t4
on April 25, 2018
|
parent
|
next
[–]
It's hard to argue about not using const, but can you remember any time where const actually prevented a bug !?
Kerrick
on April 25, 2018
|
prev
[–]
There's real value in the fact that ternary operators form
expressions
, which if statements don't.
z3t4
on April 25, 2018
|
parent
[–]
Could you elaborate ? I think the only difference is readability, where I favor if-statements over expressions.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: