Is JavaScript compiled or interpreted?

JavaScript is compiled. V8, the engine in Chrome and Node, compiles each function to bytecode the first time the program calls it, and it compiles hot code into machine code.

How it runs your code

V8 does not read your JavaScript line by line. Each function is compiled before it executes. Hot code gets another compile that produces optimized machine code. You can switch the machine code off with the --jitless flag. Other engines work differently: QuickJS runs bytecode without a JIT.

Does that make JavaScript slow?

With the JIT on, V8 runs our class code about 14 times faster than with it off, and the plain functions about 9 times faster. With the JIT off, V8 lands close to CPython.

What we measured

One small program, an order with items, a coupon, a discount and tax, written as an average programmer would write it. Times are nanoseconds per call.

SettingClass codePlain functions
JIT off (--jitless)1,699856
Optimizing compilers off (--no-opt)1,226587
Default12499

We ran the TypeScript version of the program on Node 22 with mitata, one process per setting, so the table has no spread figure. Against C++ built with -O2, V8 is 17 percent slower on the class code (124 against 106 ns) and about four times slower on the plain functions (99 against 25 ns).

Questions

Is JavaScript an interpreted language?

Not in the usual sense. V8 compiles each function before it runs, and it compiles hot code to machine code. Some small engines, such as QuickJS, run bytecode with no JIT.

Does V8 compile JavaScript to machine code?

Yes, for code that runs often. V8 first compiles functions to bytecode, then compiles hot functions to optimized machine code.

Is TypeScript compiled?

Yes. The TypeScript compiler checks types and emits JavaScript, and a JavaScript engine then runs that JavaScript.

Related

Is TypeScript compiled? · Is Python compiled? · Is Java compiled? · Compiled vs interpreted · Why optimization decides speed