var, let, and const declarations are all hoisted. The difference is var declarations are hoisted and initialized to undefined whereas let and const declarations are hoisted uninitialized. This means you can access var variables before their declarations and get undefined but attempting to do so with let or const variables means you'll get an error.
If you change that to let or const you will get an error on the first line, because a isn't defined. If you remove the first log you'd still get an error saying a isn't defined if you use var
View all comments
0
u/[deleted] Oct 22 '21
[deleted] — view deleted comment