Web Development - HTML, CSS & JavaScript: post #3640 — TG.ME

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

greet() {
console.log(`Hello, I am ${this.name}`);
}
}

const person = new Person("Deepak", 25);

person.greet();


Output:

Hello, I am Deepak

Important:

JavaScript classes are built on top of JavaScript's prototype-based inheritance.

Classes Support:

• Constructors

• Methods

• Inheritance

• Getters and setters

• Static methods

• Private fields

97. What is garbage collection?

Garbage collection is the automatic process of identifying and reclaiming memory that is no longer reachable or needed by a JavaScript program.

Developers don't normally manually free JavaScript objects.

Example:

let user = {
name: "Deepak"
};

user = null;


If the original object is no longer reachable from the program, it can eventually become eligible for garbage collection.

Important:

Garbage collection timing is determined by the JavaScript engine. You cannot normally force it from standard JavaScript code.

98. How does JavaScript manage memory?

JavaScript automatically manages memory using mechanisms such as:

1. Memory allocation

2. Program execution

3. Garbage collection

Simplified Process:

Create value



Memory allocated



Program uses value



Value becomes unreachable



Garbage collector



Memory can be reclaimed

What is a Memory Leak?

A memory leak occurs when a program unintentionally keeps references to objects that it no longer needs.

Common Causes:

• Unremoved event listeners

• Unnecessary global variables

• Timers that aren't cleared

• Large objects retained in closures

• Growing caches without limits

Example:

const cache = [];

function addData(data) {
cache.push(data);
}


If cache keeps growing indefinitely, it can consume increasing amounts of memory.

99. What are CommonJS and ES Modules?

Both are module systems used in JavaScript applications.

CommonJS

Commonly associated with Node.js and uses require() and module.exports.

// math.js
function add(a, b) {
return a + b;
}

module.exports = { add };


Import:

const { add } = require("./math");


ES Modules

The standardized JavaScript module system uses import and export.

// math.js
export function add(a, b) {
return a + b;
}


Import:

import { add } from "./math.js";


Modern JavaScript development commonly uses ES Modules, while CommonJS remains important when working with existing Node.js projects.

100. What are the latest JavaScript features introduced in ES2025 and beyond?

JavaScript continues to evolve through yearly ECMAScript releases.

For ES2025 (ECMAScript 2025), notable standardized additions include:

🔥 Iterator Helpers

Methods such as:

iterator.map(...)

iterator.filter(...)

iterator.take(...)

allow lazy processing of iterator values.

🔥 Iterator.from()

Allows an object to be converted into an iterator.

const iterator = Iterator.from([1, 2, 3]);


🔥 Set Methods

Modern Set operations include methods such as:

union()

intersection()

difference()

symmetricDifference()

Example:

const a = new Set([1, 2, 3]);
const b = new Set([3, 4, 5]);

const result = a.union(b);

console.log(result);
❤2
August 23, 2026 1.1K 4