Answers for "let var vs const"

26

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.
Posted by: Guest on May-11-2021
0

const let var

var greeter;
    console.log(greeter); // greeter is undefined
    greeter = "say hello"
Posted by: Guest on March-30-2021

Browse Popular Code Answers by Language