How does the JIT compilation of Javascript work ?

How does the JIT compilation of Javascript work ?

1.Parsing - code is parsed into a data structure - Abstract Syntax Tree

2.Compilation - Code is compiled into machine code (0s and 1s)

3.Execution - Code is directly executed after compilation (Just in time) in the JS engine's call stack

4.Optimization - Initially unoptimized code is generated. Later code is recompiled / reoptimized. This is taken care by threads , we do not have access to the code.