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
Last updated
Was this helpful?