Is JavaScript Compiled or Interpreted language?

JavaScript is a lightweight, Interpreted (or) Just In Time compiled programming language.

First Let’s understand the difference between interpreter and compiler.

Interpreter vs Compiler

Compilers and interpreters help in converting code from high-level language to machine codes to be understood by the computer. Generally, programming languages are usually written on high-level languages i.e which humans can understand. However, computers cannot understand these as we humans do. They can only understand machine code i.e 0’s or 1’s

Compiler converts (compiles) the code into another form i.e machine-readable form(byte code) before it is executed by the computer.

Eg: C/C++ is compiled into machine code which is then run by a computer.

An interpreter executes the code from top to bottom and the result of the running code is returned by the computer. Here there is no need to convert the code to machine understandable code(byte code) before the browser runs it.

Browsers execute JavaScript code as it is without converting the JS code into machine code. But most modern web browsers use JIT(Just In Time) compilers to improve the performance of the code i.e. the code gets compiled into a faster, binary format so that it can execute as soon as possible.

However, JavaScript is considered as an interpreted language as compilation is handled at run time.

References: developer.mozilla.org/en-US/docs/Web/JavaSc.., medium.com/jspoint/how-javascript-works-in-..