What Makes JavaScript Fast?

As the Web continues to evolve, it’s important for developers to understand the different technologies that enable a site’s functionality. JavaScript, along with HTML and CSS, is one of these languages that allows for more dynamic content to be created. Think about the different things you see on websites that are interactive and dynamic, such as a timeline updating on Facebook or Google suggesting search terms as you type- that’s javascript at work.

Unlike languages such as C and C++, which use ahead-of-time compilation to convert the program into machine code, JavaScript uses just-in-time compilation. This means that the program is compiled as it’s executed, which results in a more efficient and fast-running language.

Another feature that makes javascript fast is inlining, which happens when the engine inlines function calls to optimize runtime performance. When the engine encounters the first function call in the above snippet, the variable a = ‘Hi!’ gets stored in its FEC (Function Execution Context), which is layered on top of the current GEC. The next time the second function is called, instead of calling the original add() function, the engine replaces it with a return a + b statement.

This is just one example of the many optimizations that are made to help make javascript fast. The fact that it’s a single-threaded language helps as well.

Like other programming languages, javascript has a variety of data types, including primitives. Primitives are essentially basic values, such as ints, strings and dates. These are used for the most common operations. There are also reference types, which are anything that isn’t a primitive, such as objects, arrays and functions. These are called reference data types because they provide a link to the memory location where the object was created.

Lastly, there are a variety of functions in javascript that help with various tasks such as string manipulation, looping, math and handling events. There is also a built-in debugger that provides information about the execution state of a program.

In addition to all of the functionality that javascript can offer, there are also frameworks and libraries that make it easier for developers to create applications. These are especially helpful for front end development, but can also be used in back end web development.

For anyone interested in learning more about javascript, the best place to start is by installing a modern browser that supports it. Most browsers include a built-in console that can be used to enter javascript and have it executed within the context of the page. The screenshot above shows the Firefox Web Console, but most modern browsers come with a console that works in the same way. Once you’re comfortable with using the console, you can try out some simple functions by typing them into the console and pressing enter.