A High Level Overview Of JavaScript

A High Level Overview Of JavaScript

What is JavaScript?

The formal definition of JavaScript is - JavaScript is a high-level, multi-paradigm, single-threaded, dynamic programming language that has support for object-oriented programming. Quite a few heavy words right? 😵

Let's understand JavaScript as a programming language in this post.

High-level programming language

A high-level programming language is a language that provides abstraction from the computer’s internal details. In simple words, we need not worry about computer operations like memory management and allocation and all such complex stuff. We can work with different data structures like integers, floats, strings, booleans and all without worrying about the computer's architecture.

Multi-paradigm language

Multi-paradigm languages are languages that support different programming styles like object-oriented programming or functional programming or procedural programming and so on. In JavaScript, the functional programming paradigm is used extensively and JavaScript treats functions as first-class citizens. This means that functions in JS can be assigned to a variable, passed as an argument in another function and can be returned from a function. JS also has support for the object-oriented programming paradigm. We can make classes, and create objects from them, we can utilize constructor functions and JavaScript also supports setters and getters.

Single-threaded nature of JavaScript

A thread can be considered a unit that executes the code. JavaScript has only one thread for code execution. This is just to keep the language simple. But we need to be cautious about this fact. Because there is only one unit for code execution and the code is executed line-by-line, it must not be blocked. If we write code that has blocking nature (like very complex calculations or heavy input-output operations), then it will block further lines of code from being executed until the current line has finished its execution. This will slow down the process and make our programs very inefficient. However, we have features for handling such heavy operations or calculations as well in JavaScript. An example can be the prompt function available in the browsers. Until and unless we enter some value in the prompt and hit OK, the following lines of code will not be executed.

const name = prompt("Enter your full name: ");
const modifiedName = name.trim().toLowerCase();
// Other code

Dynamic Nature

Any programming language is said to be dynamic if it allows its users to manipulate data in the program dynamically, which means during the run-time. The following example illustrates the dynamic nature of JavaScript -

let x = 2;
console.log(typeof x); // prints number

x = "What's up?"
console.log(typeof x); // prints string

In this example, the data type of x has been manipulated while the code was being executed, that is, dynamically. This illustrates the dynamic nature of JavaScript. This also illustrates that JavaScript is a weakly typed language. What this means is that the data type of a variable is inferred automatically by JavaScript when we assign or re-assign a value to the variable. And the data type can be changed as well.