var:
- hoisted (always declared at top of scope, global if none)
- function scope
let:
- block scope
- not redeclarable
const:
- block scope
- not reassignable
- not redeclarable
Note: Although it may seem like these hold only semantic meaning, using the
appropriate keywords helps the JS engines' compiler to decide on what to optimize.
Posted by: Guest
on May-11-2021
7
difference between let, var and const in java script
//let is used to declare the variable or initialize a variable..
//let variable can be updated in future.
//Its block scope and we cannot redeclare it.
let a; // Initializing the variable.
let b = 4; // Initializing and declaring variable.
let b = 5; //Error:- cannot redeclare a value but we can update the value.
//var is just like let but var is used to declare a variable value at top of
//the program, its hoisted.
var a; // Initializing the variable.
var b = 4; // Initializing and declaring variable.
var b = 5; //b will be redeclared and we can update its value.
//const variable should be declared and intialized at same time.
//const variable cannot be updated in future.
//we cannot even redeclare the variable in future.
const a = 10; //Initilizing and declaring a variable at a time.
const b; //Error:- const should be declared and intialized.
const a = 11 // Error:- cannot redeclare the variable again.
Posted by: Guest
on September-15-2021
2
js var vs const
//var variables can be re-declared and updated
var greeter = "hey hi";
var greeter = "say Hello instead";
//it becomes a problem when you do not realize that a variable
//greeter has already been defined before.
//const declarations are block scoped
//const cannot be updated or re-declared
const greeting = "say Hi";
greeting = "say Hello instead";// error: Assignment to constant variable.
const greeting = "say Hi";
const greeting = "say Hello instead";// error: Identifier 'greeting' has already been declared
var:
* hoisted(global scope)
* function scope
let:
* block scope
* reassignable
* not redeclarable
const:
* block scope
* not reassignable
* not redeclarable
Posted by: Guest
on August-10-2021
0
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.
Posted by: Guest
on February-12-2021
Code answers related to "let vs const vs var in javascript"
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
Check Your Email and Click on the link sent to your email