Message from JavaScript discussions

June 2019

— Http://latentflip.com/loupe/?code=JC5vbignYnV0dG9uJywgJ2NsaWNrJywgZnVuY3Rpb24gb25DbGljaygpIHsKICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gdGltZXIoKSB7CiAgICAgICAgY29uc29sZS5sb2coJ1lvdSBjbGlja2VkIHRoZSBidXR0b24hJyk7ICAgIAogICAgfSwgMjAwMCk7Cn0pOwoKY29uc29sZS5sb2coIkhpISIpOwoKc2V0VGltZW91dChmdW5jdGlvbiB0aW1lb3V0KCkgewogICAgY29uc29sZS5sb2coIkNsaWNrIHRoZSBidXR0b24hIik7Cn0sIDUwMDApOwoKY29uc29sZS5sb2coIldlbGNvbWUgdG8gbG91cGUuIik7!!!PGJ1dHRvbj5DbGljayBtZSE8L2J1dHRvbj4%3D

Message permanent page

— 

I suggest everyone to please go through the above link, which describes "how JavaScript's call stack, event loop, and callback queue interact with each other. Visualizing the javascript runtime at runtime"

— Yesterday, I gone through those article. Awesome exploration by Philip Roberts :)

— Why does this happen

— It has always worked

— Let's say file has 4 chars
i = file.length
i will be 4
file[4] // undefined

— You should do:
let i = file.length - 1

— Because file[3] is the highest accessible int when file has length 4

— But it says nothing abouut the index variable

— Nope, it doesn't, and it shouldn't try to

— File[4] is undefined, you're passing undefined to process.stdout.write

— So do i need to roll a dice to guess what do i need to fix?