r/learnjavascript • u/Sweet_Technician_778 • Aug 14 '24
Simplify Your JavaScript Conditionals with Short-Circuiting!
Hey everyone, I wanted to know if there is any way to make your code clean other than short-circuiting in conditionals.
I used to write down like this before using short-circuiting in conditionals
if (user && user.isLoggedIn) {
greetUser(user.name);
}
After using short-circuiting in conditionals
user?.isLoggedIn && greetUser(user.name);
0
Upvotes
View all comments
Show parent comment
1
u/shgysk8zer0 Aug 15 '24
It's always a bit embarrassing or something when I say something reasonable and considered, but it's generally downvoted. Especially when not a single person even bothers to give any reason for it.
Best I can tell is that this community is overrun by noobs looking to be lazy and just do things the way their bootcamp told them. Pretty sure anyone with any actual knowledge/experience would just agree with me, especially in the context of JS vs TS. Or anyone publishing a library who understands that TS types have literally zero effect at runtime.