Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

var vs let vs const

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.
Comment

let vs const

`const` is a signal that the identifier won't be reassigned.

`let` is a signal that the variable may be reassigned, such as a counter in a
loop, or a value swap in an algorithm.

It also signals that the variable will be used only in the block it's defined
in, which is not always the entire containing function.
Comment

what is the difference between let and const in javascript

The difference is that with const you can only only assign a value to a variable
once, but with let it allows you to reassign after it has been assigned.
Comment

js var vs let

let = 10 // accessable only in defined scope
var = 10 // accessable in the function it is declared in (global variable in a function)
  
Comment

difference between var, let, const

// var is a function scope ***
if(true){
    var varVariable = 'This is var';
    var varVariable = 'This is var again';
}

console.log(varVariable); // This is var again

// let is a block scope ***
if(true){
    let letVariable = 'This is let';
    let letVariable = 'This is let again';

    // let variable can't re-define but we can re-assign value


    console.log(letVariable); // let letVariable = 'This is let again';^SyntaxError: Identifier 'letVariable' has already been declared
}

console.log(letVariable); //ReferenceError: letVariable is not defined



// const variable can't re-define and re-assign value
// const is a block scope ***
if(true){
    const constVarible = {
        name: 'JavaScript',
        age: '25 years',
    };
    constVarible.name = 'JS';

    console.log(constVarible) // {name: 'JS',age: '25 years'} <= we can update const variable declared object 
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-router useNavigate 
Javascript :: javascript change color 
Javascript :: jquery attribute 
Javascript :: discord.js remove embed from message 
Javascript :: how to get class name of element in javascript 
Javascript :: object intersection javascript 
Javascript :: indexof method 
Javascript :: how to create react native app 
Javascript :: java script strict tag 
Javascript :: how to exit node 
Javascript :: javascript moment 
Javascript :: empty check on django json field 
Javascript :: ngmodel component angular 
Javascript :: divider in react native 
Javascript :: array index javascript show only first 2 elements 
Javascript :: jquery fadein to show modal 
Javascript :: email regex javascript 
Javascript :: push object to json array 
Javascript :: page reload detect in jquery 
Javascript :: javascript async/await 
Javascript :: change li position in ul jquery 
Javascript :: javascript add dom disabled 
Javascript :: javascript create json object from array 
Javascript :: javascript filter array by groups of highest 
Javascript :: get before 6 month date javascript node js 
Javascript :: jquery remove elemtns 
Javascript :: Stop setInterval call in JavaScript 
Javascript :: blur effect javascript 
Javascript :: add an object to an array mongosse 
Javascript :: after effects loop wiggle 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =