I know that var gets hoisted in JS. So the below code gives me undefined:
i=100
function f(){
console.log(i);
var i=200;
}
f();
But I was surprised to see that the below code give me an error:
i=100
function f(){
console.log(i);
const i=200;
}
f();
Are const hoisted? If so, then why do I get an error?