VAR uses function scope, LET uses block scope CODE
Variable
variableVAR
is visible outside the
if
statement because it uses function scope instead of block scope
function callMePlease() {
  if (1 == 1) {
    let variableLET = 'LET'
    var variableVAR = 'VAR'
  }
  document.write('My ' + variableVAR + '</br>')
  document.write('My ' + variableLET + '</br>')
}

callMePlease()
Another variable
variableLET
is not visible outside the block because it uses block scope and the code above will generate the following error:
Uncaught ReferenceError: variableLET is not defined
by Valeri Tandilashvili
4 years ago
JavaScript
Variables
2
Pro tip: use ```triple backticks around text``` to write in code fences