๐ JavaScript Interview Questions with Answers โ Part 6
51. How do you sort arrays?
The
Sorting Strings
Output:
Sorting Numbers
By default,
Output:
Descending Order:
Interview Tip:
52. What is array destructuring?
Array destructuring allows you to extract values from an array and assign them to variables.
Example:
Output:
10
20
30
Skipping Values:
Output:
10 30
Default Values:
Output:
10 20
53. What are Sets?
A
Duplicate values are automatically removed.
Example:
The Set contains:
Common Methods:
Convert Set to Array:
54. What are Maps?
A
Unlike regular objects, a
Example:
Output:
Deepak
Common Methods:
Example:
Output:
true
Map vs Object:
Map
โข Any value can be a key
โข Has size property
โข Built-in methods
โข Designed for key-value collections
Object
โข Keys are primarily strings/symbols
โข No built-in size
โข Different object APIs
โข General-purpose objects
55. What are Symbols?
Example:
Output:
false
Even though both have the same description, each
Using Symbol as an Object Property:
Common Use:
56. What are generators?
Generators are special functions that can pause and resume execution.
They are created using
Example:
51. How do you sort arrays?
The
sort() method is used to sort the elements of an array.Sorting Strings
const fruits = ["Banana", "Apple", "Mango"];
fruits.sort();
console.log(fruits);
Output:
["Apple", "Banana", "Mango"]Sorting Numbers
By default,
sort() converts elements to strings, so a comparison function should be used for numbers.const numbers = [10, 5, 20, 2];
numbers.sort((a, b) => a - b);
console.log(numbers);
Output:
[2, 5, 10, 20]Descending Order:
numbers.sort((a, b) => b - a);
Interview Tip:
sort() mutates the original array.52. What is array destructuring?
Array destructuring allows you to extract values from an array and assign them to variables.
Example:
const numbers = [10, 20, 30];
const [a, b, c] = numbers;
console.log(a);
console.log(b);
console.log(c);
Output:
10
20
30
Skipping Values:
const numbers = [10, 20, 30];
const [first, , third] = numbers;
console.log(first, third);
Output:
10 30
Default Values:
const numbers = [10];
const [a, b = 20] = numbers;
console.log(a, b);
Output:
10 20
53. What are Sets?
A
Set is a collection of unique values.Duplicate values are automatically removed.
Example:
const numbers = new Set([1, 2, 2, 3, 3]);
console.log(numbers);
The Set contains:
{1, 2, 3}Common Methods:
const numbers = new Set();
numbers.add(10);
numbers.add(20);
console.log(numbers.has(10));
numbers.delete(20);
Convert Set to Array:
const arr = [...numbers];
54. What are Maps?
A
Map is a collection of key-value pairs.Unlike regular objects, a
Map can use different data types as keys.Example:
const users = new Map();
users.set(1, "Deepak");
users.set(2, "John");
console.log(users.get(1));
Output:
Deepak
Common Methods:
users.set(key, value);
users.get(key);
users.has(key);
users.delete(key);
users.clear();
Example:
console.log(users.has(2));
Output:
true
Map vs Object:
Map
โข Any value can be a key
โข Has size property
โข Built-in methods
โข Designed for key-value collections
Object
โข Keys are primarily strings/symbols
โข No built-in size
โข Different object APIs
โข General-purpose objects
55. What are Symbols?
Symbol is a primitive data type used to create unique identifiers.Example:
const id1 = Symbol("id");
const id2 = Symbol("id");
console.log(id1 === id2);Output:
false
Even though both have the same description, each
Symbol is unique.Using Symbol as an Object Property:
const id = Symbol("id");
const user = {
name: "Deepak",
[id]: 101
};
console.log(user[id]);Common Use:
Symbols are useful when you need unique property keys that are unlikely to conflict with other properties.56. What are generators?
Generators are special functions that can pause and resume execution.
They are created using
function* and use the yield keyword.Example:
โค3
function* numbers() {
yield 1;
yield 2;
yield 3;
}
const generator = numbers();
console.log(generator.next());
console.log(generator.next());Output:
{ value: 1, done: false }{ value: 2, done: false }After all values are consumed:
{ value: 3, done: false }{ value: undefined, done: true }Important:
Calling a generator function doesn't immediately execute its body. It returns a generator object.
57. What are iterators?
An iterator is an object that provides a way to access values one at a time using the
next() method.Example:
const numbers = [10, 20, 30];
const iterator = numbers[Symbol.iterator]();
console.log(iterator.next());
console.log(iterator.next());
Output:
{ value: 10, done: false }{ value: 20, done: false }The iterator eventually returns:
{ value: undefined, done: true }Common Iterables:
โข Arrays
โข Strings
โข Maps
โข Sets
That's why they can be used with
for...of.for (const number of numbers) {
console.log(number);
}58. What is destructuring assignment?
Destructuring assignment allows values to be extracted from arrays or objects and assigned to variables.
Object Example:
const user = {
name: "Deepak",
age: 25
};
const { name, age } = user;Array Example:
const numbers = [10, 20];
const [a, b] = numbers;
Why Use It?
It makes code shorter and easier to read, especially when working with API responses and function parameters.
59. What is dynamic import?
Dynamic import allows a JavaScript module to be loaded when it is needed, instead of loading it immediately.
It uses:
import()Example:
async function loadModule() {
const module = await import("./math.js");
console.log(module.add(10, 20));
}Important:
Unlike a static import:
import { add } from "./math.js";dynamic imports return a Promise.
Common Uses:
โข Lazy loading
โข Code splitting
โข Loading features only when required
โข Improving initial page performance
60. What are ES6 modules?
ES6 modules provide a standard way to divide JavaScript applications into separate files.
They use
export and import.Export:
// math.js
export function add(a, b) {
return a + b;
}
Import:
// app.js
import { add } from "./math.js";
console.log(add(10, 20));
Default Export:
export default function greet() {
console.log("Hello");
}Import:
import greet from "./greet.js";
Benefits:
โ Code organization
โ Reusability
โ Encapsulation
โ Easier maintenance
โ Avoids unnecessary global variables
โค๏ธ Double Tap For Part 7
โค1๐1
๐ช๐ข๐ฅ๐ ๐๐ฅ๐ข๐ ๐๐ข๐ ๐ ๐๐ข๐ ๐ข๐ฃ๐ฃ๐ข๐ฅ๐ง๐จ๐ก๐๐ง๐ฌ ๐
Company Name :- AI InsurTech Company
๐ผ ๐ฅ๐ผ๐น๐ฒ: Backend Developer
๐ฐ ๐ฆ๐ฎ๐น๐ฎ๐ฟ๐: โน5 LPA
๐ ๐ช๐ผ๐ฟ๐ธ ๐ ๐ผ๐ฑ๐ฒ: Work From Home
๐ ๐๐ผ๐ฐ๐ฎ๐๐ถ๐ผ๐ป: Hyderabad / Remote
๐ ๐ช๐ต๐ผ ๐๐ฎ๐ป ๐๐ฝ๐ฝ๐น๐?
โ BTech/BE graduates
โ Branches: CS, IT, AI, ML and Data-related streams
โ Graduation Years: 2025 and 2026
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐ ๐:-
https://pdlink.in/4xIfsE4
โก Apply early and share this opportunity with your friends!
Company Name :- AI InsurTech Company
๐ผ ๐ฅ๐ผ๐น๐ฒ: Backend Developer
๐ฐ ๐ฆ๐ฎ๐น๐ฎ๐ฟ๐: โน5 LPA
๐ ๐ช๐ผ๐ฟ๐ธ ๐ ๐ผ๐ฑ๐ฒ: Work From Home
๐ ๐๐ผ๐ฐ๐ฎ๐๐ถ๐ผ๐ป: Hyderabad / Remote
๐ ๐ช๐ต๐ผ ๐๐ฎ๐ป ๐๐ฝ๐ฝ๐น๐?
โ BTech/BE graduates
โ Branches: CS, IT, AI, ML and Data-related streams
โ Graduation Years: 2025 and 2026
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐ ๐:-
https://pdlink.in/4xIfsE4
โก Apply early and share this opportunity with your friends!
โค5
โ๏ธ ๐ฐ ๐๐ฅ๐๐ ๐๐ผ๐ผ๐ด๐น๐ฒ ๐๐น๐ผ๐๐ฑ ๐๐ผ๐๐ฟ๐๐ฒ๐ | ๐๐๐ถ๐น๐ฑ ๐๐ป-๐๐ฒ๐บ๐ฎ๐ป๐ฑ ๐๐น๐ผ๐๐ฑ ๐ฆ๐ธ๐ถ๐น๐น๐
Explore these Google Cloud learning resources covering cloud fundamentals, infrastructure, networking, security, data and AI/ML.
๐ฅ 4 Courses to Explore:
1๏ธโฃ Cloud Computing Fundamentals
2๏ธโฃ Infrastructure in Google Cloud
3๏ธโฃ Networking & Security in Google Cloud
4๏ธโฃ Data, ML & AI in Google Cloud
๐ ๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐:-
https://pdlink.in/4zrksPn
๐ฏ Perfect for Students | Freshers | Developers | Cloud & DevOps Aspirants
Explore these Google Cloud learning resources covering cloud fundamentals, infrastructure, networking, security, data and AI/ML.
๐ฅ 4 Courses to Explore:
1๏ธโฃ Cloud Computing Fundamentals
2๏ธโฃ Infrastructure in Google Cloud
3๏ธโฃ Networking & Security in Google Cloud
4๏ธโฃ Data, ML & AI in Google Cloud
๐ ๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐:-
https://pdlink.in/4zrksPn
๐ฏ Perfect for Students | Freshers | Developers | Cloud & DevOps Aspirants
๐ ๐๐ & ๐ ๐ฎ๐ฐ๐ต๐ถ๐ป๐ฒ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐๐ฅ๐๐ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐๐ผ๐๐ฟ๐๐ฒ
๐ฅ Upgrade your skills and prepare for exciting career opportunities in AI!
โ Beginner-friendly course
โ Learn AI & Machine Learning fundamentals
โ Gain practical, job-ready skills
โ Earn a FREE certificate
โ Boost your resume and LinkedIn profile
โ Ideal for students, freshers and professionals
๐ ๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐ ๐:-
https://pdlink.in/4zrkYNg
โก Limited opportunityโstart learning today!
๐ฅ Upgrade your skills and prepare for exciting career opportunities in AI!
โ Beginner-friendly course
โ Learn AI & Machine Learning fundamentals
โ Gain practical, job-ready skills
โ Earn a FREE certificate
โ Boost your resume and LinkedIn profile
โ Ideal for students, freshers and professionals
๐ ๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐ ๐:-
https://pdlink.in/4zrkYNg
โก Limited opportunityโstart learning today!
โค1
๐ JavaScript Interview Questions with Answers โ Part 8
71. What is fetch()?
It returns a Promise.
Example:
Using async/await:
Interview Tip:
72. What is AJAX?
AJAX stands for Asynchronous JavaScript and XML.
It is a technique for communicating with a server and updating parts of a webpage without reloading the entire page.
Despite the name, AJAX doesn't require XML. Modern applications commonly exchange JSON.
Example:
A webpage can request:
Modern Approach:
Today,
73. What are Web APIs?
Web APIs are browser-provided interfaces that allow JavaScript to interact with browser features and the environment.
Examples include:
โข
โข
โข DOM APIs
โข Local Storage
โข Geolocation API
โข Web Workers
โข Clipboard API
Example:
The timer functionality is provided by the host environment, such as a browser or Node.js runtime, rather than being part of the JavaScript language itself.
Interview Tip:
Don't confuse JavaScript language features with browser Web APIs.
74. What is setTimeout()?
Example:
The callback becomes eligible to run after approximately 2 seconds.
Important:
The delay is not a guarantee that the function executes exactly at that time.
It may execute later if the JavaScript runtime is busy.
75. What is setInterval()?
Example:
The callback runs approximately every second until the interval is cancelled.
Stop It:
Common Uses:
โข Timers
โข Polling
โข Repeated UI updates
โข Periodic tasks
76. What is clearTimeout()?
Example:
The callback will not execute because the timeout was cancelled before it became eligible to run.
Common Use:
Useful when you need to cancel a scheduled action.
77. What is clearInterval()?
Example:
71. What is fetch()?
fetch() is a modern JavaScript API used to make HTTP requests and communicate with servers.It returns a Promise.
Example:
fetch("https://api.example.com/users")
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.log(error);
});Using async/await:
async function getUsers() {
try {
const response = await fetch(
"https://api.example.com/users"
);
const data = await response.json();
console.log(data);
} catch (error) {
console.log(error);
}
}Interview Tip:
fetch() rejects its Promise for network-level failures, but an HTTP error such as 404 or 500 does not automatically reject it. You should check response.ok.72. What is AJAX?
AJAX stands for Asynchronous JavaScript and XML.
It is a technique for communicating with a server and updating parts of a webpage without reloading the entire page.
Despite the name, AJAX doesn't require XML. Modern applications commonly exchange JSON.
Example:
A webpage can request:
User data โ Server
โ
JSON
โ
JavaScript
โ
Update webpage
Modern Approach:
Today,
fetch() is commonly used instead of the older XMLHttpRequest API.73. What are Web APIs?
Web APIs are browser-provided interfaces that allow JavaScript to interact with browser features and the environment.
Examples include:
โข
fetch()โข
setTimeout()โข DOM APIs
โข Local Storage
โข Geolocation API
โข Web Workers
โข Clipboard API
Example:
setTimeout(() => {
console.log("Hello");
}, 1000);The timer functionality is provided by the host environment, such as a browser or Node.js runtime, rather than being part of the JavaScript language itself.
Interview Tip:
Don't confuse JavaScript language features with browser Web APIs.
74. What is setTimeout()?
setTimeout() schedules a function to run after a specified delay.Example:
setTimeout(() => {
console.log("Hello");
}, 2000);The callback becomes eligible to run after approximately 2 seconds.
Important:
The delay is not a guarantee that the function executes exactly at that time.
It may execute later if the JavaScript runtime is busy.
75. What is setInterval()?
setInterval() repeatedly schedules a function at approximately specified intervals.Example:
const interval = setInterval(() => {
console.log("Running...");
}, 1000);The callback runs approximately every second until the interval is cancelled.
Stop It:
clearInterval(interval);
Common Uses:
โข Timers
โข Polling
โข Repeated UI updates
โข Periodic tasks
76. What is clearTimeout()?
clearTimeout() cancels a timeout that was previously scheduled using setTimeout().Example:
const timer = setTimeout(() => {
console.log("Hello");
}, 5000);
clearTimeout(timer);The callback will not execute because the timeout was cancelled before it became eligible to run.
Common Use:
Useful when you need to cancel a scheduled action.
77. What is clearInterval()?
clearInterval() stops an interval created using setInterval().Example:
let count = 0;
const interval = setInterval(() => {
count++;
console.log(count);
if (count === 5) {
clearInterval(interval);
}
}, 1000);
Output:
1
2
3
4
5
After 5, the interval is stopped.
78. What is callback hell?
Callback hell occurs when multiple asynchronous operations are nested inside one another, making code difficult to read and maintain.
Example:
getUser(user => {
getOrders(user, orders => {
getPayment(orders, payment => {
processPayment(payment, result => {
console.log(result);
});
});
});
});This creates deeply nested code.
Problems:
โ Difficult to read
โ Difficult to debug
โ Difficult to maintain
โ Error handling becomes complicated
79. How do you avoid callback hell?
Several approaches can make asynchronous code cleaner.
1. Use Promises
getUser()
.then(getOrders)
.then(getPayment)
.then(processPayment)
.catch(handleError);
2. Use async/await
async function process() {
try {
const user = await getUser();
const orders = await getOrders(user);
const payment = await getPayment(orders);
await processPayment(payment);
} catch (error) {
console.log(error);
}
}3. Break large functions into smaller functions
Instead of putting everything into one deeply nested callback, separate responsibilities into reusable functions.
Interview Tip:
For modern JavaScript, Promises and async/await are the most common solutions.
80. What are microtasks and macrotasks?
This is an important advanced JavaScript interview topic.
The JavaScript runtime has different queues for asynchronous work.
Microtasks
Examples include:
โข Promise callbacks
โข
queueMicrotask()โข MutationObserver callbacks in browsers
Macrotasks / Tasks
Common examples include:
โข
setTimeout()โข
setInterval()โข Some browser events
Example:
console.log("Start");
setTimeout(() => {
console.log("Timeout");
}, 0);
Promise.resolve().then(() => {
console.log("Promise");
});
console.log("End");Output:
Start
End
Promise
Timeout
Why?
After the synchronous code finishes, the runtime processes available microtasks before moving to the next task.
So:
Synchronous code
โ
Microtasks
โ
Next task / macrotask
โค๏ธ Double Tap For Part 9
โค1
๐ ๐ช๐ถ๐ฝ๐ฟ๐ผ ๐๐น๐ถ๐๐ฒ ๐ก๐ง๐ & ๐ง๐๐ฟ๐ฏ๐ผ ๐๐ฅ๐๐ ๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐๐ถ๐ ๐ป๐ฅ
Get access to a FREE interview preparation kit and prepare smarter for your upcoming assessment & interview rounds.
๐ Prepare For:-
โ Technical Interview Questions
โ Software Engineer Interview Rounds
โ Interview Preparation Resources
๐ฏ Perfect for Students | Freshers | Engineering Graduates | Wipro Aspirants
๐ ๐๐ฒ๐ ๐๐ฅ๐๐ ๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐๐ถ๐ ๐:-
https://pdlink.in/4zh9E6g
๐ฅ Start preparing early and improve your chances of cracking the Wipro hiring process!
Get access to a FREE interview preparation kit and prepare smarter for your upcoming assessment & interview rounds.
๐ Prepare For:-
โ Technical Interview Questions
โ Software Engineer Interview Rounds
โ Interview Preparation Resources
๐ฏ Perfect for Students | Freshers | Engineering Graduates | Wipro Aspirants
๐ ๐๐ฒ๐ ๐๐ฅ๐๐ ๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐๐ถ๐ ๐:-
https://pdlink.in/4zh9E6g
๐ฅ Start preparing early and improve your chances of cracking the Wipro hiring process!
๐ฃ๐ฎ๐ ๐๐ณ๐๐ฒ๐ฟ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐โ๐๐ฒ๐ฐ๐ผ๐บ๐ฒ ๐ฎ ๐๐๐น๐น ๐ฆ๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ ๐๐ถ๐๐ต ๐๐ฒ๐ป๐๐๐
Curriculum designed and taught by alumni from IITs & leading tech companies.
๐ Placement Highlights:-
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ partner companies
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐ ๐:-
https://pdlink.in/3SuUeuD
โก Take the first step toward your dream tech career today!
Curriculum designed and taught by alumni from IITs & leading tech companies.
๐ Placement Highlights:-
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ partner companies
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐ ๐:-
https://pdlink.in/3SuUeuD
โก Take the first step toward your dream tech career today!
๐ JavaScript Interview Questions with Answers โ Part 10
91. What is throttling?
Throttling limits how frequently a function can execute within a given time interval.
Even if an event fires many times, the function is allowed to execute at most once during each interval.
Example:
Common Uses:
โข Scroll events
โข Mouse movement
โข Window resizing
โข Continuous user interactions
Debounce vs Throttle:
Debounce โ Execute after activity stops
Throttle โ Execute at controlled intervals
92. What is memoization?
Memoization is an optimization technique where the result of a function is cached so that the same calculation doesn't have to be performed again.
Example:
Example Usage:
The first call performs the calculation.
The second call can use the cached result.
Benefits:
โ Faster repeated calculations
โ Avoids unnecessary work
Drawback:
โ Uses additional memory for cached results.
93. What is currying?
Currying transforms a function that takes multiple arguments into a sequence of functions that each take one argument.
Normal Function:
Curried Function:
Usage:
Output:
Arrow Function Version:
Common Uses:
โข Functional programming
โข Creating reusable functions
โข Partial application
โข Configuration-based functions
94. What is prototype inheritance?
JavaScript uses objects as the foundation of its inheritance system.
Objects can access properties and methods through their prototype chain.
Example:
Although dog doesn't directly contain speak(), it can access the method through its prototype.
Prototype Chain:
dog
โ
animal
โ
Object.prototype
โ
null
JavaScript searches this chain when a property isn't found directly on the object.
95. What is prototypal inheritance?
Prototypal inheritance is JavaScript's mechanism for allowing one object to inherit behavior from another object through the prototype chain.
Example:
Here:
student has its own study() method.
greet() comes from its prototype, person.
96. What are classes in JavaScript?
Classes provide a cleaner syntax for creating objects and implementing object-oriented programming patterns.
Classes were introduced in ES6.
Example:
91. What is throttling?
Throttling limits how frequently a function can execute within a given time interval.
Even if an event fires many times, the function is allowed to execute at most once during each interval.
Example:
function throttle(callback, delay) {
let lastTime = 0;
return function(...args) {
const now = Date.now();
if (now - lastTime >= delay) {
lastTime = now;
callback.apply(this, args);
}
};
}Common Uses:
โข Scroll events
โข Mouse movement
โข Window resizing
โข Continuous user interactions
Debounce vs Throttle:
Debounce โ Execute after activity stops
Throttle โ Execute at controlled intervals
92. What is memoization?
Memoization is an optimization technique where the result of a function is cached so that the same calculation doesn't have to be performed again.
Example:
function memoize(fn) {
const cache = new Map();
return function(n) {
if (cache.has(n)) {
return cache.get(n);
}
const result = fn(n);
cache.set(n, result);
return result;
};
}Example Usage:
function square(n) {
console.log("Calculating...");
return n * n;
}
const memoizedSquare = memoize(square);
console.log(memoizedSquare(5));
console.log(memoizedSquare(5));The first call performs the calculation.
The second call can use the cached result.
Benefits:
โ Faster repeated calculations
โ Avoids unnecessary work
Drawback:
โ Uses additional memory for cached results.
93. What is currying?
Currying transforms a function that takes multiple arguments into a sequence of functions that each take one argument.
Normal Function:
function add(a, b, c) {
return a + b + c;
}
console.log(add(1, 2, 3));Curried Function:
function add(a) {
return function(b) {
return function(c) {
return a + b + c;
};
};
}Usage:
console.log(add(1)(2)(3));
Output:
6
Arrow Function Version:
const add = a => b => c => a + b + c;
Common Uses:
โข Functional programming
โข Creating reusable functions
โข Partial application
โข Configuration-based functions
94. What is prototype inheritance?
JavaScript uses objects as the foundation of its inheritance system.
Objects can access properties and methods through their prototype chain.
Example:
const animal = {
speak() {
console.log("Animal speaks");
}
};
const dog = Object.create(animal);
dog.speak();Although dog doesn't directly contain speak(), it can access the method through its prototype.
Prototype Chain:
dog
โ
animal
โ
Object.prototype
โ
null
JavaScript searches this chain when a property isn't found directly on the object.
95. What is prototypal inheritance?
Prototypal inheritance is JavaScript's mechanism for allowing one object to inherit behavior from another object through the prototype chain.
Example:
const person = {
greet() {
console.log("Hello");
}
};
const student = Object.create(person);
student.study = function() {
console.log("Studying");
};
student.greet();
student.study();Here:
student has its own study() method.
greet() comes from its prototype, person.
96. What are classes in JavaScript?
Classes provide a cleaner syntax for creating objects and implementing object-oriented programming patterns.
Classes were introduced in ES6.
Example:
โค1
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);
โค1
๐ฅ Regular Expression Improvements
ES2025 also introduced improvements to regular expressions, including support for enhanced Unicode-related matching capabilities.
๐ฅ Promise.try()
โ ๏ธ Important Interview Point
JavaScript features are standardized through the ECMAScript specification, and browser/Node.js support can vary by feature and version.
So when discussing "latest JavaScript," distinguish between:
Standardized features
โ Officially included in an ECMAScript release.
Proposed features
โ Still moving through the TC39 proposal process.
Runtime support
โ Whether a particular browser or Node.js version actually supports the feature.
Double Tap โค๏ธ For More
ES2025 also introduced improvements to regular expressions, including support for enhanced Unicode-related matching capabilities.
๐ฅ Promise.try()
Promise.try() provides a convenient way to turn a synchronous function call into a Promise-based operation.Promise.try(() => {
return someFunction();
});โ ๏ธ Important Interview Point
JavaScript features are standardized through the ECMAScript specification, and browser/Node.js support can vary by feature and version.
So when discussing "latest JavaScript," distinguish between:
Standardized features
โ Officially included in an ECMAScript release.
Proposed features
โ Still moving through the TC39 proposal process.
Runtime support
โ Whether a particular browser or Node.js version actually supports the feature.
Double Tap โค๏ธ For More
โค2
๐ ๐๐ฅ๐๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐๐ผ๐๐ฟ๐๐ฒ! ๐
Hereโs a great chance to learn valuable skills and earn a FREE Certificate ๐
โ Beginner-friendly
โ Learn Data Analytics skills
โ Free certification
โ Boost your resume & LinkedIn profile
โ Great for students & job seekers
๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐ :-
https://pdlink.in/4qn5q94
๐ Start learning today & upgrade your career!
Hereโs a great chance to learn valuable skills and earn a FREE Certificate ๐
โ Beginner-friendly
โ Learn Data Analytics skills
โ Free certification
โ Boost your resume & LinkedIn profile
โ Great for students & job seekers
๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐ :-
https://pdlink.in/4qn5q94
๐ Start learning today & upgrade your career!