js-by-examples
js-by-examples copied to clipboard
Can I help update the declaration of variables?. A good practice!
Scope
let var const
function hi () { alert("hi") }
hi = function () { alert("hello") }
console.log(hi()); //"hello"
better
const hi = function () { alert("hi") }
hi = function () { alert("hello") }
console.log(hello); // Uncaught TypeError: invalid assignment to const 'hi'
let obj = {};
obj = "string"; //"string"
better
const obj = {};
obj = "string"; // Uncaught TypeError: invalid assignment to const 'obj'