ABSTRACT

Computers don't execute JavaScript directly. Instead, every processor has its own instruction set; compilers translate high-level languages into those instructions. To learn more about how this works, this chapter constructs a simulation of a tiny processor with a few bytes of memory and a handful of instructions. As small as it is, this virtual machine can perform complex calculations comprised of loops and conditionals. While the virtual machines that full-strength languages such as JavaScript and Python rely on are much larger and more sophisticated, they operate on the same principles; understanding those principles can help with debugging and performance optimization.