var, let , const in Javascript – Scope of Variables

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

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *