DEV Community

let, const, and my view

EmNudge on December 26, 2019

"Well this isn't going to be a controversial post" he said, wrongly. For those unaware, the title is in reference to a little discussion that span...
Collapse
 
aviaryan profile image
Avi Aryan • Edited

Same here.

By default, I write const and then only switch to let if I need to change a variable. If you write code functional programming style (which is better IMO), you won't be using let. I almost don't use let at all.

Collapse
 
moopet profile image
Ben Sinclair

As mentioned before, const only serves to make a constant binding, not data structure, but that is not immediately obvious to a beginner.

I don't use JS as my main language, but I've been using it since corduroy was cool and that wasn't obvious to me.

Collapse
 
andevr profile image
drew

Nice post. I'm still a newbie learner, so I'll have to google some things, but overall this made sense. I've been a bit confused over this, and I think a lot of courses on Udemy are teaching let over const, but from the viewpoint of skimming code and expecting a change with let, that makes a lot of sense. Gonna bookmark this post and come back to it when I pick up JS again. Thanks.

Collapse
 
emnudge profile image
EmNudge • Edited

I'm glad you found my post so helpful!

As an aside, my posts are usually aimed at people who already know quite a bit, but I try to also add some language for people who are new, but extra curious.

The fact that you still understood it means a lot to me!

Collapse
 
jeroenrombouts profile image
Jeroen Rombouts

I used to think like you. Then I started working in an environment where I'm about the only real front-end developer and the others are repurposed WinForms developers. You don't want to know how many times I get the question why their const can be mutated.

So, yes, in theory you're right. In some environments, however, prefer-let makes more sense. I'm all for changing your approach based on your environment and/or project instead of thinking in absolutes.

Collapse
 
yoadev profile image
Younes

Very interesting article, I always wanted to know which way should I use. I can make my opinion now, thank you !

Collapse
 
zakwillis profile image
zakwillis

Thanks for the article. Interesting.

Collapse
 
juancarlospaco profile image
Juan Carlos

If you combine let and const you left ~10% of users with broken code.
For Backend is Ok whatsoever.