InterviewHubPRO
Section Overview
Q1

Question 1 of 521

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

0%
JavaScript Internals (521 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What is JavaScript, and what are its core architectural characteristics?

In Simple Words: JavaScript is a high-level, dynamically typed, single-threaded, prototype-based, multi-paradigm interpreted (JIT-compiled) programming language. Originally created by Brendan Eich in 1995 for Netscape, JavaScript conforms to the ECMAScript specification (ECMA-262) and is the foundational execution language of the Web, modern backend servers (via Node.js, Deno, Bun), and mobile runtimes.

Key Architectural Characteristics:

  1. Single-Threaded Execution: Uses a single main thread for executing JavaScript code, governed by an Event Loop that delegates I/O, timers, and network operations to host environments without blocking.
  2. Dynamic & Weak Typing: Types are associated with runtime values, not variable declarations. Variables can be reassigned to any type, and implicit type coercion is performed when evaluating different types.
  3. Prototype-Based Object-Oriented: Objects inherit directly from other objects via prototype chains rather than relying strictly on class blueprints.
  4. First-Class Functions: Functions are treated as first-class citizens; they can be stored in variables, passed as arguments to other functions, and returned from functions (higher-order functions and closures).
  5. JIT (Just-In-Time) Compilation: Modern JavaScript engines (like Google V8, SpiderMonkey, JavaScriptCore) don't simply interpret source code line by line; they parse code into an Abstract Syntax Tree (AST), compile it into bytecode, and dynamically optimize hot functions into machine code at runtime.

Practical Code Example

javascript
// 1. Dynamic Typing & Introspection
let dynamicValue = "Hello, JavaScript";
console.log(typeof dynamicValue); // "string"

dynamicValue = 42;
console.log(typeof dynamicValue); // "number"

// 2. First-Class Functions & Higher-Order Functions
function createMultiplier(multiplier) {
  // Returns an inner function forming a closure over 'multiplier'
  return function (num) {
    return num * multiplier;
  };
}

const double = createMultiplier(2);
const triple = createMultiplier(3);

console.log(double(10)); // 20
console.log(triple(10)); // 30

// 3. Prototype-based inheritance in action
const vehicleProto = {
  drive() {
    return `Driving ${this.model || 'vehicle'} on ${this.wheels} wheels`;
  }
};

const car = Object.create(vehicleProto);
car.model = "Tesla Model 3";
car.wheels = 4;

console.log(car.drive()); // "Driving Tesla Model 3 on 4 wheels"
console.log(Object.getPrototypeOf(car) === vehicleProto); // true