JavaScript let
This keyword is used to declare variables locally. If you use this keyword to declare a variable then the variable can be accessible locally and it is changeable as well. It is good if the code gets huge.
Syntax:
let variableName = "Variable-Value;"
Example: This example shows the use of let.
if (true) {
let geeks = "w3wiki";
console.log(geeks);
}
/* This will be error and
show geeks is not defined */
console.log(geeks);
Output
w3wiki
How to declare variables in different ways in JavaScript?
In JavaScript, variables can be declared using keywords like var, let, or const, each keyword is used in some specific conditions. Understanding these declarations is crucial for managing variable lifetimes and avoiding unintended side effects in code.
Table of Content
- JavaScript var
- JavaScript let
- JavaScript const
- Difference Between var, let, and const