const vs let in Javascript - short notes


const vs let in javascript


https://mathiasbynens.be/notes/es6-const - understdood

To simply put.
let allows to reassign or modify a data type
const allows assign data type only once and never allow to reassign it.
let letVar = {"key" : "value"}
undefined
letVar
Object { key: "value" }

searchvinoptions response not available yet.... MainComponent.js:188
letVar = "hey i am a string"
"hey i am a string"

const constVar = "string data type being binded to constVar which is not reassignable"
undefined
constVar
"string data type being binded to constVar which is modifyable but not reassignable"
constVar = {}
TypeError: invalid assignment to const `constVar'[Learn More] debugger eval code:1:1

constVar = "i am also a string; but i cannot be reassigned to constVar now"
TypeError: invalid assignment to const `constVar'[Learn More] debugger eval code:1:1

```

short note:
const also allows to modify the value of the same data type without reassigning. for example, say const variable type holds array type. you can push or pop the values inside it as long as you do not reassign that const variable

```JAVASCRIPT
const constVarArrayType = []
undefined
searchvinoptions response not available yet.... MainComponent.js:188
constVarArrayType.push("i an modify array value here")
1
constVarArrayType
Array [ "i an modify array value here" ]

constVarArrayType = "but i cannot change already const assigned value of it"
TypeError: invalid assignment to const `constVarArrayType'[Learn More] debugger eval code:1:1

Comments