Airscript Learn to use Airtable scripts

var, let and const

If you’re a new coder and looking at scripts written by others, some of the syntax and coding conventions can be confusing. Why are there many ways to do the same thing and why doesn’t everyone do it the same way?

Why do some coders use:


var i;
for (i = 0; i < cars.length; i++) {
  console.log(cars[i])
}

and others use:


for (let i of cars) {
  console.log(i)
}

Like spoken languages, programming languages develop and change over time, so part of the reason is that new language specifications bring us new ways of coding.

One of the most fundamental concepts to understand is the declaration of variables and how this changed with the introduction of Javascript ES6. When do you use let and const (and what’s the difference)? Can I still use var?

Here’s a great article from FreeCodeCamp that breaks it all down.