I'm probably missing something very fundamental but I would like to ask this regardless

```
var a=100;
function f(){
    console.log(a)
    const a=150
}
console.log(a)
f(); 

```

Prints 100 and throws an error while changing const a=150 to var a=150 returns 100 and undefined. I'm unsure why this behavior occurs and any pointers to relevant info is appreciated