difference in var let and const
var:
* hoisted(global scope)
* function scope
let:
* block scope
* reassignable
* not redeclarable
const:
* block scope
* not reassignable
* not redeclarable
difference in var let and const
var:
* hoisted(global scope)
* function scope
let:
* block scope
* reassignable
* not redeclarable
const:
* block scope
* not reassignable
* not redeclarable
difference between var let and const in javascript with example
//functional scope
var a; // declaration
a=10; // initialization;
//global scope
// re-initialization possible
let a;//only blocked scope & re-initialization possible
a=10;
let a =20;
if(true){
let b =30;
}
console.log(b); // b is not defined
const // const also blocked scope,Re-initialization and re-declaration not possible
const a; // throws error {when we declaring the value we should assign the value.
const a =20;
if(true){
const b =30;
}
console.log(b); // b is not defined
console.log(a); // no output here because code execution break at leve b.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us