How does JS even work?
- v8 (chromes run time)
- single threaded
- callbacks
js says...
"a signle-threaded non-blocking asynchronous concurrent language" "i have a call stack, an event loop, a callback queue, and some other apis"
v8 says... "i have a call stack and a heap"
the call stack one thread == one call stack == on thing at a time
call stack records where we are in the program
"blowing the stack" => too many functions (infinite recur)
one thing at a time, except not really runtime can only execute one line of code at a time BUT Browser is more than just runtime! Calling WebAPIs opens additional threads outside js (In node, this is C++ APIS)
webAPI finishes, pushes callback onto TASK QUEUE event loop continuously checks stack when stack is empty, moves callback off TASK QUEUE and pushes onto hte stack
eg setTimeOut(0, callback) defers callback until stack is empty