Functions
Functions in JavaScript are first class citizens.
When a function is created, the JavaScript engine first checks the syntax. After that:
- Allocated memory for a new function object.
- Attaches the function body, lexical environment map, etc
- Returns the function reference ID. This is like a pointer to where the function lives in memory.
functions not always recreated
Normal functions - the reference is created once, on first use. After that, the same reference is reused.
Child functions - the function object is created each time the parent runs. Every function has its own lexical environment. It's built during the run and garbage-collected after.