var keyword

var

  • In recent past var was the only way to declare variables

  • While var worked it presented some annoying issues (related to scope) for developers

  • let and const were introduced in the latest release of JavaScript, ES6 to address these issues

  • While var is still in use for legacy codebases, it is a recommended best practice to use let or const(we’ll discuss const shortly) instead of var going forward

// declaring a variable using var
var name = "Jen"

// declaring a variable using const (or let) (best practice)
const name = "Jen"

Click here for more information on the differences between let and var