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.
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.
Alright, so our targeted audience is mostly comprised of people who are in their early stages of the coding journey and are just getting started, if you check our profile you will find most of the tutorial belong to that category only.
One of the main reasons we prefer to limit our audience is so that we can match the requirements of a beginner and make sure our explanation is understandable to them.
Or is it that let doesn't add any real benefit in this case - and it is noisier as it requires a separate line of code just for the declaration.
And I don't understand what you mean with "will break if I cover everything with ES6 block scope".
they whole problem if the hoisting of var. Block Scope is safer in your daily programming. Why to I need to care of hoisting.?
try{varsomething=createSomething();// something is now available in the whole function / global}finally{if(something)something.freeResources();}
You only need to free resources when you doing something you don't wan't anything to access it later. The garbage collector will do the rest for you. So this example is shit. If you know how to program without side effects there is no real case you would go into this.
var could causing side effects if you don't carefully watch that you don't need it in the function. It has no benefit except you call hoisting one. So you want hoisting. And in my opinion (because that's all here) its shit.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
its because var is not realy declaring a variable like let or const, with var you adding something to this.
So this works:
var a = "a";
console.log(this.a); // 'a'
This not:
let a = "a";
console.log(this.a) // undefined
So every time you use var its like adding something to this. Thats the "function scope".
It seems that var outperforms both let and const in 2017.
quora.com/What-is-the-performance-...
Thanks for sharing. Im gonna work it through and look if this still the case. 9 years difference (according to the engineer discussion)
Hey Lars! I will be replying to this comment of yours:
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.
Alright, so our targeted audience is mostly comprised of people who are in their early stages of the coding journey and are just getting started, if you check our profile you will find most of the tutorial belong to that category only.
One of the main reasons we prefer to limit our audience is so that we can match the requirements of a beginner and make sure our explanation is understandable to them.
I hope this answers your question!
Have a great day!
2021-Feb-25:
Context:
doesn't work because of the block scope
const something
is constrained to.var
is scoped to the execution context sowill work. Otherwise one needs to resort to
Just because you don't use it doesn't mean that it isn't useful.
var
add no real benefit overlet
in the case, and will break if I cover everything with ES6 block scopeOr is it that
let
doesn't add any real benefit in this case - and it is noisier as it requires a separate line of code just for the declaration.And I don't understand what you mean with "will break if I cover everything with ES6 block scope".
var
can be scoped with IIFE, unless you expect scope leak.let
andconst
can be scoped with just{}
alone.One line of code doesn't matter that much (unless TypeScript - you need to and
let
type declaration).I don't want to see this kind of bug.
If that is an issue, an entirely different conversation is necessary: Why is this type of code running in the Global Scope?
var
is constrained (does not leak) within functions and within modules - so nothing about ES2015 or ESNext will make code that usesvar
"break".f(m)
going to get undetected given thatm
is going to beundefined
?m
?m
anyway - likely two different names are more intention revealing.In the majority of cases
let
andconst
are better - but that doesn't mean all cases.they whole problem if the hoisting of var. Block Scope is safer in your daily programming. Why to I need to care of hoisting.?
You only need to free resources when you doing something you don't wan't anything to access it later. The garbage collector will do the rest for you. So this example is shit. If you know how to program without side effects there is no real case you would go into this.
var could causing side effects if you don't carefully watch that you don't need it in the function. It has no benefit except you call hoisting one. So you want hoisting. And in my opinion (because that's all here) its shit.