Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I not use var in ES6? [duplicate]

Tags:

javascript

I am sorry if this is asked already but as I am introducing myself in ES6 on some tutorials, the instructor is saying that the var statement should be avoided. It just feels wrong but, is there any good reason for why should it be avoided?

like image 408
learningjavascriptks Avatar asked Dec 06 '25 03:12

learningjavascriptks


1 Answers

var is on ES6 for legacy reasons. In theory, the let statement is better since it behaves more predictably on block scopes, but it won't work with more outdated interpreters. So, if you're coding with only ES6 in mind, go for let.

EDIT: Also, keep in mind that if you're new to JS, you'll likely find more learning material using var, so keep that in mind.

like image 98
Rafael Avatar answered Dec 07 '25 17:12

Rafael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!