Declare Variables

let user = 'John', 
	age = 25, 
	message = 'Hello';
// Note: no "use strict" in this example
num = 5; // the variable "num" is created if it didn't exist
alert(num); // 5
"use strict";
num = 5; // error: num is not defined

var Differences

if (true) {
  var test = true; // use "var" instead of "let"
}
alert(test); // true

for (var i = 0; i < 10; i++) {
  // ...
}
alert(i); // 10, "i" is visible after loop, it's a global variable
function sayHi() {
  if (true) {
    var phrase = "Hello";
  }

  alert(phrase); // works
}

sayHi();
alert(phrase); // Error: phrase is not defined

Hoisting

function sayHi() {
  phrase = "Hello";
  alert(phrase);
  var phrase;
}