DEV Community

Cover image for What is JS an interpreted language?
Manu Martinez
Manu Martinez

Posted on

What is JS an interpreted language?

Interpreted language, it could sound petty strange, so rare, however do not get scare I will explain you whatever you need to make you one of the best JS developer.

Understanding the difference
There is two types of programming languages, compiled and interpreted ones. It's indicate how the code is understanding by the computer. Maybe you have heard talk about machine code with a lot of:

101010101
01010101010
0101010101001
010101010101010
Enter fullscreen mode Exit fullscreen mode

compiled-representation

Yeah I know, the code looks so difficult, I am sure you do not understand anything (If yes please let me know I will invite you a coffee πŸ˜†) This is machine code, the code that all computers understand in the world, nevertheless it so hard for us and this is the reason why programming languages exist. The process that perform the translation between any programming language to machine code is called Compilation, it's typical in C++, Swift and other high level languages.

Otherwise, interpretation is different, in this process the interpreter (commonly the bowser) read each line and execute the action, when the action finished he continue with the next sentence of code. Maybe you can think it's better but not at all. Exits a program call pre compiler who help you to avoid errors during coding, for instance, if you wrong write the var name he will show an alert saying this error. Then, JS is an interpreted language.

How it works?

JavaScript allocates in memory all variables and functions using during execution time. It's mean that all data is allocated in RAM when the code is running, it's allow us to have faster access to the data.

Look at the following example πŸ˜‡:

const myName = "Manu";
console.log(myName);
Enter fullscreen mode Exit fullscreen mode

When you run your code JS interpreted look the first line and detect an assignment, you have created a new memory space for the String Manu, interpreted allocates in memory this data, then continue with the second line and say a sentence which allow us to print some data in console, JS look for the value of myName in the memory (with the reference it provide you in the allocation process) and print this value in console.

interpreted-representation

JS looks petty good, it's easier to understand that other programming languages and maybe it's the reason why JS is interpreted, the learn curve is less exponential.

Anything else πŸ˜‹?

Javascript has dynamic type, it's mean that variable types are defining during interpretation process, not before. It can bring us some errors during executing due to miss or wrong types. When you declare a var or constant in JS you do not have to indicate the type, it's automatically assigned. Some people think it's not a problem, but it's clearly a huge disadvantage since you get confuse when you are coding and commit some errors but you will not be alert until code is running. It avoid us to prevent execution errors.

Look at the following examples:

const surname = "Martinez";
const myAge: Number = 20;
Enter fullscreen mode Exit fullscreen mode

The difference is really easy, in the first sentence a dynamic typed language (JS) you do not have to indicate the value type, it's automatic, however the second one is static typed language where you have to indicate the value type in each assignment. It's really petty exiting, with JS you do not have to think in data types, merely you have to focus on learn and create amazing algorithms.

You know, forget all data types and focus on learning process, you will become a great JS developer πŸ‘¨πŸ»β€πŸ’» in the future.

Top comments (0)