If I write this then it prints undefined:
let a
console.log(a)
a = 20
but why does this return an error, then?
console.log(a)
let a = 20
a
gets hoisted to the top in case 2 and since JavaScript doesn’t assign any value to let in memory allocation phase it returns error. But isn’t the condition similar in case 1 also? Then why does it print undefined in case 1?