DEV Community

Cover image for What is JavaScript ?
Gaurav Sharma
Gaurav Sharma

Posted on

What is JavaScript ?

What is JavaScript ?

JavaScript is a high-level prototype-based object oriented Multiparadigm, interpreted or just in time compilated dynamic, single Treaded, garbage collected programming language with first-class functions and a non-blocking event loop concurrency module.

๐ŸคฏDon't Worry Let's break above definition into points.๐Ÿ‘‡

  • High-level
  • Garbage-Collection
  • Interpreted or just in time compiled
  • Multi-paradigm
  • Prototype-based object-oriented
  • First class functions
  • Dynamic
  • Single-Threaded
  • Non-blocking event loop

๐ŸŒŸNow Let's discuss each point in detail.

1. JavaScript is High-Level

๐ŸŸกEvery program that runs on our computer needs some hardware resources such as memory and the cpu to do its work.

๐ŸŸกThere are low level languages like C where we have to manually manage these resources.

On the other side we have high level languages like python and JavaScript 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.

2. JavaScript has Garbage-Collection

๐ŸŸก It is basically an algorithm inside the JavaScript engine that removes old, unused objects from the computer memory

๐ŸŸก JavaScript cleans our memory from time to time so that we don't have to do it manually in our code

3. JavaScript is interpreted or Just-in-time compiled

๐ŸŸก Computer processor ultimately understands 0 or 1 every single program needs to be written in binary language which is also called machine code.

๐ŸŸก That is not practical to right that's why we write human-readable code.

Like JavaScript 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.

๐ŸŸก Above step is necessary in every single programming language.

๐ŸŸก Because no one write machine code manually. IN case of JavaScript This happens inside the JavaScript engine.

4. JavaScript is Multi-paradigm language

๐ŸŸก In programming a paradigm is an approach overall mindset of structuring our code. Which will ultimately direct the coding style and technique in a project that uses a certain paradigm.

๐ŸŸก Some popular programming paradigm are:-

  • Procedural Programming
  • Object-oriented programming (OOP)
  • Functional Programming

5. JavaScript has prototype-based, object-oriented approach.

๐ŸŸก All most everything in JavaScript is an object except of primitive values.

๐ŸŸก But arrays, for example are just object.

๐ŸŸก Now, have you ever wondered why we can create an array and then use the push method on it

๐ŸŸก It's because of "prototypal inheritance". Basically we create arrays from an array blueprint which is like template and this is called the prototype.

๐Ÿ‘‰ I will create a separate thread ๐Ÿงต on prototypal inheritance.

6. JavaScript is a language with first class function

๐ŸŸกIn a language with first-class functions, functions are simply treated as variables. We can pass them into other functions, and return them from functions.

๐ŸŸกWhich means functions are treated as regular variables

๐ŸŸกSo, we can pass functions into other functions and we can even return functions from functions.

7. JavaScript is Dynamic

๐ŸŸกJavaScript is a dynamic language which means dynamically-typed language

๐ŸŸกIn JavaScript we don't assign data types to variables, instead they only become known when the JavaScript engine executes our code.

Image description

8. JavaScript is Single-Threaded

๐ŸŸก Before know what is single threaded we need to know about the "Concurrency Model"

๐ŸŸก Well "Concurrency Model" is a fancy term that means how the JavaScript engine handles multiple tasks happening at the same time.

๐ŸŸก JavaScript itself runs in one single-thread which means it can only do on thing at a time and therefore we need a way of handling multiple things at the same time.

๐ŸŸกBy the way in computing a thread is like a set of instructions that is executed in computer's CPU

๐ŸŸก So basically, the thread is where our code is actually executed in a machine's processor.

๐ŸŸก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 right.

๐ŸŸก But we don't want that. what we want is

๐ŸŒŸ Non-blocking behavior and how do we achieve that. Well by using a so-called event loop. The event loop takes long-running tasks, executes in the background and put's them back in the main thread

๐ŸŸก This is in a nutshell JavaScript's non-blocking event loop concurrency model with a single thread

Top comments (0)