Stop using var for declaring variables
If you are new to JS or been with it for quite some time then for the most part you probably be u...
For further actions, you may consider blocking this person and/or reporting abuse
Using const only means that the variable will always have a reference to the same object or primitive value, because that reference can’t change. The reference itself is immutable, but the value held by the variable does not become immutable.
Hello Ibrahim, thanks for the explanation but it's probably too complex for our targeted audience, we will try to simplify your explanation and update our post accordingly.
Have a great day!
What target is that? the "I just learned to walk"? Constants are a basic concept of programming. And to point out that a Javascript const is not the same as a C const is not to hard.
Also you're completely right and I don't know why var still exist.
For historical purposes, i.e. backward compatibility.
they could deprecate it. Like other stuff. It could be used but with a warning. In all MSDN docs you will find var declarations. That's not just about backward compatibility.
Biggest major oddness about var, apart from hoisting and function scoped, is that you can declare it multiple times.
Nice explanation of concepts, I really liked it.
The only thing I can't agree with is the title of the post. There is no point of avoiding
varaltogether if you understand its scope and impact.Hey Vaishali!
We are very glad to hear that you liked our post :D
And yes we understand your concern regarding the title, I'll report it to my editor. But our main goal here is not to make judgemental titles, instead, we try to emphasize the overall takeaway of the post, we love people like you who always come forward and share their views and opinions about every single aspect of our work!
Thank you once again and have a really great day!
Sorry for directly targetting the title but the only point I wanted to make is that though
letandconstare good addition to the language,varstill holds its value and is still useful in many cases.I love JS ♥️ and even though ES6 is booming, I still respect ES5 for its simplicity 👍
Can you give an example where
varis better? I've never come across one (unless targeting ES5 without transpilation for some reason).Did I say
varis better? 🤔Can you give example of an application which would be impossible to develop without
letandconst?letandconstare not essential features, they are just good to have things. With their introduction,vardoesn't become obsolete. That was my point 😊You didn't say it's better overall, you said it's "useful in many cases". That's what I was asking for clarification about, because in my experience it's only useful as a transpilation target — when writing your own code,
constandletalways have better semantics and lead to fewer bugs. But I was curious as to what your counterexamples would be.There are still use cases to use var, are we going to see those too?
Thanks for the suggestion Mundo! Will send this to our editorial team!
And yes var hai its use cases but talking about ES6, using let and const are considered as best practices for modern web application development.
Have a great day Mundo!
How about we just throw JavaScript out of equation and glorify Jquery and it's sugar coated syntaxes!
Although, I'd point out:
a const is a constant, and not a variable.
Haha, this headline is usually whisper yelled thru my teeth.