DEV Community

Discussion on: javascript question - Hoisting

Collapse
 
wakwe profile image
Olisa Wakwe • Edited

I don't think hoisting applies to vars, so the first console.log(a) should cause an error to be thrown as "a" doesn't exist yet.

Collapse
 
sanjeevpanday profile image
sanjeev

Hoisting is applicable to variables as well.

Both variables and functions are put into memory during context creation ( or compile ) phase.

Variables declared with var keyword will get initialized with value undefined during context creation phase.

So you would not get error for first console.log(a)