ES6+ for React
  • Introduction
  • Introduction
    • Introduction
  • Statements and declarations
    • let
    • const
    • class
    • import
    • export
  • Standard built-in objects
    • Arrow functions
    • Template literals
    • Array.prototype.map()
    • Computed property names
  • Expressions and operators
    • Spread operator
    • Destructuring assignment
    • Logical Operators
Powered by GitBook
On this page
  • Defination
  • Syntax
  • Examples
  • Usage
  • References

Was this helpful?

  1. Statements and declarations

let

Defination

The let statement declares a block scope local variable, optionally initializing it to a value.

Syntax

let var1 [= value1] [, var2 [= value2]] [, ..., varN [= valueN]];

Examples

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

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

Usage

function Title(props) {
  let content = props.content
  return (
    <h1>{content}</h1>
  )
}

References

PreviousIntroductionNextconst

Last updated 4 years ago

Was this helpful?

MDN let