DEV Community

Discussion on: 17 Javascript optimization tips to know in 2021 ๐Ÿš€

 
andrewbridge profile image
Andrew Bridge • Edited

I agree, it reads nicely enough, but what's the benefit to this over:

let test2 = 'between 50 and 100';
if (x > 100) { test2 = 'greater 100'; }
else if (x < 50) { test2 = 'less 50'; }
Enter fullscreen mode Exit fullscreen mode

It's dealers choice with regard to using an else statement or default assignment as above and the formatting isn't my cup of tea, but it's still nevertheless the same statement on three lines. IMO, this is still way clearer and I don't see any downside to it.