High-level overview of Javascript
Tags: javascript, webdev, programming, tutorial
Published: 2022-10-06 14:17:05

Javascript is a <strong>`high-level`</strong> <strong>`prototyped-based object oriented`</strong> <strong>`multi-paradigm`</strong> <strong>`interpreted or just-in-time compiled`</strong> <strong>`dynamic`</strong> <strong>`single-threaded`</strong> <strong>`garbage-collected`</strong> programming language with <strong>`first-class functions`</strong> and a non-blocking <strong>`event loop concurrency model`</strong>.

## High-Level
Every program on your computer needs hardware resources such as memory and the CPU to do its work. Now, there are low-level languages, such as C where you have to manually manage these resources. e.g asking the computer for memory to create a new variable. on the other side, you have high-level languages such as javascript and python, where we do not have to manage resources at all because these languages have so-called abstractions that take all of the work away from us. This makes the language easier to learn and use, but the downside is that programs will never be as fast or as optimised as C programs.

## Garbage collected
Garbage collection is basically an algorithm inside the javascript engine that automatically removed old, unused objects from the computer memory to avoid clogging it up with necessary stuff. So it's a bit like JavaScript has a cleaning guy who cleans our memory from time to time so that we don't have to manually do it in our code.

## Interpreted or just-in-time compiled
As we know that the computer’s processor only understands zeros and ones, that’s right. Ultimately, every single program needs to be written in zeros and ones which is also called machine code. And since that’s not really practical to write. We simply write human-readable javascript code, which is an abstraction over machine code, but this code eventually needs to be translated to machine code. And that step can be either compiling or interpreting. This step is necessary in every single programming language because no one writes machine code manually, in the case of javascript, this happens inside the javascript engine.

## Multi paradigm
A paradigm is an approach and mindset to structuring code, which will direct your coding style and technique. eg. Procedural programming, object-oriented programming and functional programming. Now, many languages are only procedural or only object-oriented or only functional, but JavaScript does all of it. So it's really flexible and versatile. And so we can do really whatever we want with it. It's our choice. We can use whatever paradigm we want. 

## Prototype-based object-oriented
So about the object-oriented nature of Javascript, it is a prototype-based, object-oriented approach. Well, first almost everything in javascript is an object, except for primitive values such as numbers, strings etc. but arrays, e.g are just objects. Have you ever wondered why we can create an array and then use the push method on it? Well, it’s because of prototypal inheritance. Basically, we create arrays from an array blueprint, which is like a template and this is called the prototype. This prototype contains all the array methods and the arrays that we create in our code and then inherit the methods from the blueprint so that we can use them on the arrays. 

## First-class function
It just simply means that functions are treated as regular variables., So we can pass functions into other functions and this is extremely powerful because it allows us to use a lot of powerful techniques and also allows for functional programming

## Dynamic
Dynamic actually means dynamically typed, in javascript we don’t assign data types to variables. Instead, they only became known when the javascript executes out code. Also, the type of variables can be easily changed as we reassign variables, and this is basically whey dynamically typed means.

## Single-threaded & Non-blocking event loop
It just means that javascript can do one thing at one time. So basically, the thread is where our code is actually executed in a machine’s processor. all Right. But what if there is a long-running task? like fetching data from a remote server? Well, it sounds like that would block the single thread where the code is running. But of course, we don’t want that.  What we want is so-called non-blocking behaviour. Well by using a so-called event loop. The event loop takes long-running tasks, executes them in the background and then puts them in the background and then puts them back in the main thread once they are finished.


> Source: [Jonas Schmedtmann Udemy Course](https://www.udemy.com/course/the-complete-javascript-course/)

Feel free to connect me on [LinkedIn](https://linkedin.com/in/shubhamku044), [Twitter](https://twitter.com/shubhamku044) and [My website](https://shubhams.dev/)