High-level overview of JavaScript

High-level overview of JavaScript

Learn JavaScript by heart

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

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

Feel free to connect me on LinkedIn, Twitter and My website

Did you find this article valuable?

Support Shubham Sharma by becoming a sponsor. Any amount is appreciated!