JavaScript Variables and Scope
In ES6 JavaScript, there are four ways to define a variable:
// gobal definition
age = 25;
// function scoped
var age = 25;
// block scoped
let age = 25;
// block scoped without reassignment
const age = 25;
In general, we should always strive to use let
and const
in our code to avoid bugs and improve readability.