Should You Truly Never Use var? – John Wolfe – Medium

Should You Truly Never Use Var?  #ecmascript6 #ydkjs #javascript #variables #react #reactjs

  • No error is thrown if you declare the same variable twice using var (conversely, both let and const will throw an error if a variable is declared twice)2.
  • So using var in this context would require a situation in which a variable declared inside a function would need to be used in the global scope.
  • I conducted a quick search on the Internet revealed that and, and did not raise an issues with the use of var as a variable declaration.
  • Kyle Simpson, author of You Don’t Know JS, and all-around Javascript guru, in this article, has argued for a possible case for var.
  • Simpson argues that:“There are going to be places in real world code where some variables are going to be properly scoped to the entire function, and for those variables, var is a better signal”He provides this code block to illustrate his point:Essentially, Simpson is arguing that while changing var with…

Some controversy in the Javascript community has emerged over this classic variable declaration. So, are the E6 purists correct and we should forever delegate var to the dustbin? This blog post will…
Continue reading “Should You Truly Never Use var? – John Wolfe – Medium”