Doubt regarding Node js intro

WHy does a undefined at line 9 but if we do the sam operation inside the readFile call back function , it prints value ? This is the image

This is due to the fact that readfile is an aynchronus function and doesnt give the data right away
If you give a set timeout to the vairable a outside the block it will not give undefined
As the console.log of a is executed before the data is fetched from file and stored in the variable a

1 Like