If you decided one day to go into a discussion about Javascript, you will probably hear words like high-level, garbage-collected, interpreted, multi-paradigm, dynamic, prototype-based, and single-threaded, which may turn you into 🥱, 😵💫 or 🤨.
Each of these words explains an aspect of javascript, and putting them all together will help draw a mental image of javascript, the main goal of this writing, is to build this mental image 🤝.
Let’s start 🏁
High-level 👀: It simply means, we do not have to worry about the hardware staff, that’s it 🤷♀️.
Each program that runs on a computer needs some hardware resources, to do its work. Some programming languages are designed to be more developer-friendly, which means enabling the developers to focus on the functionality of the program rather than the low-level details of machine instructions, such as Python and Javascript these are called high-level programming languages.
Garbage collection 🧹: This is an algorithm inside the javascript engine that automatically removes old unused variables from the computer memory, to not block it with unnecessary stuff.
Oh, and for the weird word engine, do not worry we are going to discuss it in detail in another writing 🤞, temporarily consider it as a Javascript lab, it is where the javascript code is executed.
Interpreted 👩💻: Saying that Javascript is an interpreted language, is not 100% true, let’s break this down…
There are two main ways for a programming language to be translated into machine language 0s & 1s, compiling and interpreting.
Javascript uses a combination of the two techniques, so it is not purely an interpreted language.
You may now wonder, so why it is famed as an interpreted language?!!
There are many reasons for this that we may discuss later but for now, let’s say it is a kind of label javascript earned in its earliest days as browsers’ engines were mainly dependent on interpreting for code execution.
Multi-paradigm 🤓: a programming paradigm is a mindset and style in code structure flow and techniques.
The point is that some programming languages are limited to a single paradigm unlike Javascript, you choose your favourite paradigm and Javascript will stay as powerful as it is✌️, this is a kind of flexibility, don't you agree🤔?!
With the mention of flexibility, let’s discuss…
Dynamic 🕶: While using a dynamically typed language we do not need to explicitly set a variable data type, in other words, in dynamically typed languages data types are associated with values, not with the variables this explains why when it comes to initialising a variable in javascript we do not need to set a specific data type to it, it is just set when the code is executed, and we are still able to change a variable datatype by reassigning it, the debate around if this considered a pro or a con of JavaScript is there, but it is out of our scope.
Prototype-base 🧬: In JavaScript, almost everything has a template from which we can simply make a copy, this copy we can modify as much as we can but it still INHERITS the features of the main template we cloned it from. The template is what is called a prototype.
Now let's move to our last term which is…
Single-threaded 🫡: We can think of the word thread as it means task, so when we say single-threaded it means managing one task at a time, let’s try to understand this a little bit better.
There is a tight relationship between the core design of a programming language and the environment this language runs on.
Some programming languages are designed on their core to support multiple threads, like Python for example, while others are not like Javascript.
There should be a kind of harmony between a programming language and the environment it runs on, so if a language supports multiple threading the environment it runs on has to support it, otherwise, the language’s multithreading capabilities would be disabled which will cause many errors and unexpected behaviour, depending on the core code of the program.
Javascript was originally designed to make web pages more vivid, and browsers are single-threaded by nature, so even if the Javascript core is designed to handle multiple threading it wouldn't be useful in the traditional sense of web pages.
In light of the previously mentioned points, you may wonder, since JS code execution is done sequentially if any code takes a long time to execute, it will block anything that needs to be executed after that, but as we are interacting with web pages this does not seem to be the case!! so how 🤔?!!
The answer to this question requires going through the process of JavaScript code execution which we may cover in another writing, but simply, there is an execution mechanism in browsers that takes asynchronous actions, actions with delays e.g. API calls, to be handled away from the main thread, then these actions get back again to the main thread once they are done, this is not so nuanced, just to cut a long story short.
Hope this helps and thanks for reading. If you have any questions or topics you want me to write about I will be happy to help❤️.
Top comments (0)