Difference between Var ,Let ,Const
- var
- let
- const
var declaration example
var name= 'cse'
var is the globally scoped , function/locally scoped.
The scope is global when the variable is declared outside a function.
This means that any variable that declared with the var keyword outside a function block is globally scoped.
var is the function scoped where it declared within the function.
var can be updated or re-declared.
var variable which is not declared automatically it takes the value as undefined.
let declaration example
let name= 'cse'
let is the locally scoped or block scoped. let variable can be live within the curly braces {}.
let can be updated but not re-declared.
where let keyword is not declared or initialized then automatically it takes the value as Reference error.
Const declaration example
variable declares with the const value it maintains as constant.
const name= 'cse'
Like let declaration,const value only be accessed within the block they were declared.
const value cannot be updated or re-declared.
Thanks for reading :)