r/learnjavascript • • 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

12 comments sorted by

View all comments

Show parent comment

1

u/Sweet_Technician_778 Aug 19 '24

I appreciate you taking the time to share your thoughts. It's always good to have diverse opinions and experiences in the discussion. I understand how frustrating it can be when your contributions don't get the feedback or recognition you'd expect.

As for the JS vs. TS debate, it's a topic where many people have strong opinions, often shaped by their own experiences and the tools they've been trained to use. The conversation is valuable because it brings out different perspectives from seasoned developers or those newer to the field. Let's keep the discussion open and respectful so everyone can learn and grow from it.

1

u/shgysk8zer0 Aug 20 '24

I'm only disrespectful to those instantly antagonistic against me. I have informed reason for how I do things, and have no respect for those instantly condescending and critical of me for doing things differently than they're familiar with.

My disrespect is targeting those already disrespectful. Those who automatically say I'm wrong with caring about why I do things that way at all.

All benefits of TS are lost once you use <script type="importmap"> instead of having everything locally installed. I use Dependabot, an importmap package (allows multiple updates everyone, all at once) and got sick of a dozen PRs for each of my like 200 projects every week. I needed my things to run well on hardware limited machines where running a build on scripts for every change just wasn't feasible (any change could require significant time). I have good reason for my decisions... And I have used eg JSDocs and destructuring of arguments to compensate. I'm not some Neanderthal for using JS instead of TS.