0

With ES6, I've stated using let keyword, instead of var.

Recently, in one of my code base, I didn't find any issue with removing var with let in 10000+ lines of code.

I know the difference between var and let, but is there any practical reason where we should prefer var over let?.

Aᴍɪʀ
  • 7,623
  • 3
  • 38
  • 52
Daksh Gupta
  • 7,554
  • 2
  • 25
  • 36
  • 3
    Backwards compatibility. – trincot Jan 16 '17 at 07:59
  • Read [this](http://softwareengineering.stackexchange.com/questions/274342/is-there-any-reason-to-use-the-var-keyword-in-es6). – Aᴍɪʀ Jan 16 '17 at 07:59
  • Check this: [Is there any reason to use the “var” keyword in ES6?](http://softwareengineering.stackexchange.com/questions/274342/is-there-any-reason-to-use-the-var-keyword-in-es6) – Yosvel Quintero Jan 16 '17 at 08:00
  • 1
    You said `I know the difference between var' and 'let`, then you said `but is there any practical reason where we should prefer 'var' over 'let'` you seem to be contradicting yourself – Trash Can Jan 16 '17 at 08:00
  • Thanks for the info – Daksh Gupta Jan 16 '17 at 08:04
  • You've said you're using `let` everywhere now instead of `var`. Consider using `const` when you can -- which is surprisingly often. – T.J. Crowder Jan 16 '17 at 08:05
  • I find it useful as a shorthand in variable initialization: `if (a) {var b = ...} ... if (b) { doStuff(); }`. This avoids the awkward-looking split declaration and initialization: `let b; if (a) {b = ...} ... if (b) { ... }`. – Stefan Dragnev Jan 16 '17 at 09:53

0 Answers0