Recently I have come across the concept of Hoisting in which Js arrange all the variables and functions at the top of the program before executing it. But there is a problem I came across a lot like if I execute a variable before declaring it. It causes the error of undefined or you can say it is the initial value of that given by the hoisting to that variable. But after assigning it a value still giving the same error.
console.log(aVar); // undefined
console.log(aLet); // causes ReferenceError: aLet is not defined
var aVar = 1;
let aLet = 2;
Is there something I am missing or Not Know like what is the point of Hoisting here. I want to know what is the correct way to use hoisting without get the undefined value.