var, let and const are used to store values. The scope these data types are little different. So we gonna check that out in this post.
const – for storing constant data
var – for storing variable data
let – for storing variable data
Scope of var, let, const in javascript
Inside a function
var x = 5 ; // Local
let y = 6; // Local
const z = 5; // Local
Outside a function
var x = 5 ; // Global
let y = 6; // Global
const z = 5; // Global
if/else, for/while
var x = 5 ; // Global
let y = 6; // Local
const z = 5; // Local