JavaScript - An Overview

What is JavaScript?

JavaScript gives life to a website. It is because of JavaScript that we as users can fill out names in an online form, filter dresses by popularity on an e-commerce website, and listen to our favorite music on Spotify.

JavaScript is a synchronous, single-threaded scripting language.

Let us understand each of the above-highlighted terms.

  • Synchronous

    By synchronous, we mean that any line of code gets executed only after the code before has been executed, howsoever time it might take.

    Whilst it is good to some extent, it has many cons.

    If there is a time taking code and the code after it is independent of the former then it makes no sense to delay the execution of the latter.

    This is where we need to introduce asynchronous behavior to JavaScript.

  • Single-threaded

    We can understand this with a simple analogy.

    Suppose there is a restaurant with just one cook.

    If there is an order for rice, this same cook has to boil water, wash the rice and finally prepare the rice.

    Had there been 2 or more cooks, the work could have been done fast.

    Here, the case of one cook is analogous to being single-threaded.

    JavaScript being a single-threaded language can execute only one task at a time. Which also means that it does not allow parallel processing.

  • Scripting language

    There are two types of languages in the world of computers:-

    Compiled & Interpreted

    Compilation happens for the entire code all at once.

    Interpretation means the execution of code after every single line.

    We can see this effect when running JavaScript code in the browser's console.

    As soon as we hit enter after one line of code, it gets executed.

    Python is another example of a Scripting language.

    I hope you found this article helpful.

    See you in the next one!

    Happy learning! :)