Javascript "let" & "const"
Allanki Srinivas (He/Him)
Passionate full-stack developer with a decade of experience. Always put the client’s needs first, to find a perfect balance between time, money, and functionality.
- Variables declared with var are read/write but exhibit some unexpected characteristics, especially for developers coming from c+ +, java and c#.
- Because of this confusion and other reasons, two new keywords( let and const) for declaring variables were added in es2015
- Declaring variables with let and const behave as most developers expiated
- Variables are defined within a block scope and there is no hoisting.
- Variables defined with cost are immutable, while variables defined with let are mutable.
- When declaring variables, always prefer const to let, unless there is a specific reason for a variable to be mutated.