JavaScript is a single-threaded, dynamically typed, interpreted programming language that supports multiple programming paradigms, including object-oriented, functional, and imperative styles. Its features provide prototype-based object orientation and an event-driven architecture. making it well-suited for building interactive and asynchronous web applications.

didn't get much idea with this definition, let's explore each part of it's definition in details

🧵Single Threaded: JavaScript is single-threaded, meaning it has only one main thread of execution. This means it uses a single call stack to manage function execution.

When a function is called, it is pushed onto the top of the call stack. Once the function finishes executing, it is popped off the stack, and control returns to the next item below. JavaScript code is executed in a sequential manner, one step at a time.

Despite being single-threaded, JavaScript provides Web APIs (like setTimeout, fetch, and Event Listeners) that allow asynchronous operations. These APIs work with the event loop and callback queue to handle asynchronous tasks without blocking the main thread.

console.log("Start");

setTimeout(() => {
  console.log("Inside setTimeout"); // runs later
}, 1000);

console.log("End");

// Output:
// Start
// End
// Inside setTimeout

Dyamically Type:
In JavaScript, variables are not explicitly declared with a type. Instead, their types are inferred from the values assigned to them at runtime. This means a variable can hold a value of one type and later be reassigned to a value of a completely different type during the program’s execution.

let data = 10;       // data is a number
data = "hello";      // now it's a string
data = true;         // now it's a boolean

console.log(typeof data); // Output: boolean
  • This flexibility makes JavaScript powerful but also prone to type-related bugs if not handled carefully.

Interpreted Language:
JavaScript is an interpreted language, which means the code is read, interpreted, and executed line by line at runtime, rather than being compiled ahead of time like some other languages (e.g., C++ or Java).

However, modern JavaScript engines in browsers (like V8 in Chrome) use Just-In-Time (JIT) compilation to enhance performance. JIT compiles frequently used code on the fly during execution, combining the benefits of both interpretation and compilation.

let message = "Hello, Gurnav!";
console.log(message); // Output: Hello, Gurnav!

Object Oriented: Object-Oriented Programming (OOP) is a paradigm that organizes code around objects, which are instances of classes. JavaScript supports OOP by allowing you to create and work with objects to encapsulate data and behavior.

Although the class syntax was introduced in ES6 (ECMAScript 2015) for cleaner and more familiar OOP syntax, JavaScript is fundamentally built on prototype-based inheritance under the hood.

class Person {
  constructor(name) {
    this.name = name;
  }

  greet() {
    console.log(`Hi, I'm ${this.name}`);
  }
}

const user = new Person("Gurnav");
user.greet(); // Output: Hi, I'm Gurnav

Imperative Programming:
Imperative programming is a programming paradigm that focuses on how to perform tasks step by step using explicit statements and control flow (like loops, conditionals, and assignments).

In this style, you tell the computer what to do and how to do it, modifying program state along the way.

const numbers = [1, 2, 3, 4];
const doubled = [];

for (let i = 0; i < numbers.length; i++) {
  doubled.push(numbers[i] * 2);
}

console.log(doubled); // [2, 4, 6, 8]

Functional Programming:
Functional programming is a paradigm where programs are constructed by applying and composing pure functions. It emphasizes what to do rather than how to do it.

Key principles include:

  • Pure functions (no side effects)

  • Immutability (data is not modified)

  • First-class functions (functions can be passed around like variables)

  • Higher-order functions (functions that take or return other functions)

  • Function composition: Building complex functionality by combining simpler functions.

const numbers = [1, 2, 3, 4];

const doubled = numbers.map(num => num * 2);

console.log(doubled); // [2, 4, 6, 8]

🧬 Prototype-Based Orientation:
JavaScript uses prototype-based object orientation, which means that objects inherit directly from other objects, rather than from classes (like in classical OOP languages).

Every JavaScript object has an internal link to another object called its prototype. When you try to access a property or method that doesn't exist on the object itself, JavaScript looks for it in the object's prototype chain.

Even the class syntax in JavaScript is just syntactic sugar over this prototype-based inheritance.

function Person(name) {
  this.name = name;
}

// Adding method to the prototype
Person.prototype.sayHi = function () {
  console.log(`Hi, I'm ${this.name}`);
};

const user = new Person("Gurnav");
user.sayHi(); // Hi, I'm Gurnav

note: sayHi is not directly on user, but JavaScript finds it through the prototype chain.

⚡ Event-Driven Architecture:
Event-driven architecture is a programming model where the flow of the program is determined by events — such as user actions (clicks, typing), messages from other programs, or timers.

In JavaScript, especially in the browser environment, this is a core concept. JavaScript uses event listeners to react to events asynchronously without blocking the main thread. This allows for building highly interactive and responsive applications.

id="greetBtn">Say Hello


  const button <span class="o">= document.getElementById<span class="o">(<span class="s2">"greetBtn"<span class="o">)<span class="p">;

  button.addEventListener<span class="o">(<span class="s2">"click", <span class="o">() <span class="o">=> <span class="o">{
    alert<span class="o">(<span class="s2">"Hello, Gurnav!"<span class="o">)<span class="p">;
  <span class="o">})<span class="p">;

Here, JavaScript listens for the "click" event. When the event happens, the callback function is executed.

Real-world use cases:

  • Button clicks

  • Form submissions

  • Keyboard input

  • Mouse movements

  • API responses (like fetch)

  • Timers (setTimeout, setInterval)