Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

Latest commit

 

History

History
30 lines (25 loc) · 639 Bytes

01-a-let.md

File metadata and controls

30 lines (25 loc) · 639 Bytes

let

Background

let is another way to declare variables. let is block scoped. More reading: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let

example-link

function varTest() {
  var x = 1
  if (true) {
    var x = 2 // same variable!
    console.log("varTest: x = " + x) // 2
  }
  console.log("varTest: x = " + x) // 2
}

function letTest() {
  let x = 1
  if (true) {
    let x = 2 // different variable
    console.log("letTest: x = " + x) // 2
  }
  console.log("letTest: x = " + x) // 1
}

varTest()
letTest()