Sitemap

KY JavaScript

23 min readAug 3, 2025

--

✅ 1. What is JavaScript?

JavaScript is a simple programming language that makes websites interactive. It allows things like button clicks, animations, forms, and data updates to happen without reloading the whole page.

OR

javascript is a interpretted language it can be more attractive web page by user interface

Hinglish:-

JavaScript ek interpreted language hai jo user interface ki help se web pages ko zyada attractive bana sakti hai.

✅ 2. What is JavaScript Explain the diffrence between var, let and const.?

  • var: Declares a function-scoped variable that can be redeclared and reassigned.
  • let: Declares a local-scoped variable that can be reassigned but not redeclared.
  • const: Declares a block-scoped constant that cannot be reassigned or redeclared.

Hinglish:-

  • var: Function-scoped variable declare karta hai jise redeclare aur reassign dono kar sakte hain.
  • let: Block-scoped variable declare karta hai jise reassign kar sakte hain but redeclare nahi kar sakte.
  • const: Block-scoped constant declare karta hai jise na reassign kar sakte hain aur na redeclare.

✅ 3. What are data types in JavaScript?

JavaScript has 2 data types:

Data Type:-

A data type defines the type of value stored in a variable

OR

A data type represents the type of value that can be stored in a variable

OR
A data type determines the type of value a variable can hold

Hinglish:-

Data Type:
Data type batata hai ki variable me kis type ki value store ho sakti hai.

Primitive Types:

  • String
  • Number
  • Boolean
  • Null
  • Undefined
  • Symbol (ES6)
  • BigInt (ES11)

Non-Primitive (Reference Type):

  • Object (includes Arrays, Functions, etc.)

✅ 4. What is Array in JavaScript ?

Array is a linear data structure which store multiple value in a continous manner.

Hinglish:-

Array ek linear data structure hai jo multiple values ko continuous tarike se store karta hai.

✅ 5. What is hoisting in JavaScript?

Hoisting is JavaScript’s behavior of moving declarations to the top of the current scope (function or global).

Hinglish:-

Hoisting JavaScript ka behavior hai jisme declarations ko current scope (function ya global scope) ke top par move kar diya jata hai.

console.log(a); // undefined
var a = 5;

✅ 6. Explain the concept of “undefined” vs. “null”.

  • undefined: A variable declared but not assigned any value.
  • null: A variable that is clearly set to no value.

Hinglish:-

  • undefined: Variable declare hua hai but usme koi value assign nahi hui.
  • null: Variable ko intentionally empty ya no value set kiya gaya hai.
let x;
console.log(x); // undefined

let y = null;
console.log(y); // null

✅ 7. What are JavaScript functions, and how do you define them?

A function is a reusable block of code that performs a specific task.

Hinglish:-

Function ek reusable block of code hota hai jo ek specific task perform karta hai.

// Function declaration
function greet(name) {
return "Hello " + name;
}

console.log(greet("Rahul")); // Hello Rahul
// Function expression
const greet = function(name) {
return "Hello " + name;
};

// Arrow function (ES6)
const greet = (name) => "Hello " + name;

✅ 8. What is an Immediately Invoked Function Expression (IIFE)?

An IIFE is a function that runs immediately after it is defined.

Hinglish:-

IIFE (Immediately Invoked Function Expression) ek aisa function hota hai jo define hote hi turant execute ho jata hai.

(function() {
console.log("IIFE runs immediately!");
})();

✅ 9. What is the purpose of the this keyword?

this refers to the object that is executing the current function.

  • In a method: this refers to the object.
  • Alone or in a regular function: this is the global object (window in browser).
  • In strict mode: this is undefined.

OR

The this keyword refers to the object that is currently executing the code.

OR

The this keyword in JavaScript refers to the object that is currently executing the code.
Its value depends on how and where the function is called:

  • In a regular function, this refers to the global object (or undefined in strict mode).
  • In a method, this refers to the object that owns the method.
  • In an event handler, this refers to the element that received the event.
  • In an arrow function, this does not have its own value — it uses this from the outer scope.

Hinglish:-

this keyword us object ko refer karta hai jo currently code execute kar raha hota hai.

const person = {
name: "Rahul",
greet() {
console.log("Hi, I'm " + this.name);
}
};

person.greet(); // Hi, I'm Rahul

✅ 10. What is scope in JavaScript?

Scope determines the accessibility (visibility) of variables.

Types:

  • Global Scope: Accessible everywhere
  • Local/Function Scope: Accessible inside functions
  • Block Scope (with let/const): Accessible inside {} blocks

✅ 11. Explain closures and how they work.

A closure is created when a function remembers its outer lexical environment, even after that outer function has finished executing.

Hinglish:-

Closure tab banta hai jab ek function apne outer lexical environment ko yaad rakhta hai, even outer function ke execute hone ke baad bhi.

function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
};
}

const counter = outer();
counter(); // 1
counter(); // 2

✅ 12. What is an object in JavaScript?

An object is a collection of key-value pairs where keys are strings (or Symbols), and values can be any data type, including functions.

Hinglish:-

Object key-value pairs ka collection hota hai jisme keys strings (ya Symbols) hoti hain aur values kisi bhi data type ki ho sakti hain, including functions.

const person = {
name: "Rahul",
age: 25,
greet: function () {
console.log("Hello!");
}
};

✅ 13. How do you create an object in JavaScript?

There are several ways:

// 1. Object literal
const obj1 = { name: "Rahul" };

// 2. Using `new Object()`
const obj2 = new Object();
obj2.name = "Rahul";

// 3. Constructor function
function Person(name) {
this.name = name;
}
const obj3 = new Person("Rahul");

// 4. Using Object.create()
const obj4 = Object.create(null);
obj4.name = "Rahul";

✅ 14. What is the difference between Object.keys() and Object.values()?

  • Object.keys(obj) returns an array of the keys of the object.
  • Object.values(obj) returns an array of the values of the object.
const user = { name: "Rahul", age: 25 };

console.log(Object.keys(user)); // ["name", "age"]
console.log(Object.values(user)); // ["Rahul", 25]

✅ 15. What is the difference between synchronous and asynchronous JavaScript?

  • Synchronous: Code is executed line by line, blocking the execution of the next line until the current line finishes.
  • Asynchronous: Code is non-blocking, and execution can continue while waiting for an operation to complete.

Hinglish:-

  • Synchronous: Code line by line execute hota hai, aur next line tab tak wait karti hai jab tak current line complete na ho jaye.
  • Asynchronous: Code non-blocking hota hai, aur execution continue rehta hai jab tak koi operation complete hone ka wait ho raha ho.
// Example of asynchronous code
setTimeout(() => {
console.log("Hello after 2 seconds");
}, 2000);

✅ 16. What are callbacks, and how do they work?

A callback is a function passed as an argument to another function, to be called after some operation is done.

OR

A callback is a function passed as an argument to another function, so it can be called later.

Hinglish:-

Callback ek function hota hai jo kisi dusre function ko argument ke roop me pass kiya jata hai, taaki use baad me call kiya ja sake.

function greet(name, callback) {
console.log("Hi " + name);
callback();
}

function sayBye() {
console.log("Goodbye!");
}

greet("Rahul", sayBye);

// Output:
// Hi Rahul
// Goodbye!

✅ 17. Explain Promises and how they work and Promise.all.

Promise is a javaScript future result. if success goes to .then if fail goes to .catch and it is two parameter resolve and reject

OR

A Promise in JavaScript is an object that represents the eventual completion of an asynchronous operation.
It’s used to handle async tasks like fetching data from an API, reading files, etc., without blocking the main thread.

OR

A Promise is an object in JavaScript that represents the future result of an asynchronous operation.
It is used to handle tasks like fetching data from an API or reading files without blocking the main thread.
A promise has two parameters — resolve and reject:

  • If the task succeeds, it goes to .then()
  • If the task fails, it goes to .catch()

Hinglish:-

Promise:
Promise JavaScript me ek object hota hai jo kisi asynchronous operation ke future result ko represent karta hai. Agar success hota hai to .then() run hota hai aur agar fail hota hai to .catch() run hota hai. Isme do parameters hote hain: resolve (success) aur reject (failure).

const promise = new Promise((resolve, reject) => {
let success = true;
if (success) {
resolve("Success!");
} else {
reject("Failed!");
}
});

promise
.then((res) => console.log(res))
.catch((err) => console.error(err));

States of a Promise:

  • P ending: initial state
  • Resolved (fulfilled): operation completed successfully
  • Rejected: operation failed

🔸 Promise.all()

Promise.all() takes an array of promises and returns a single Promise that:

  • Resolves when all promises succeed
  • Rejects if any one fails

Hinglish:-

Promise.all():
Promise.all() ek array of promises leta hai aur ek single promise return karta hai. Ye tab resolve hota hai jab saare promises success ho jayein, aur agar ek bhi fail ho jaye to ye reject ho jata hai.

Promise.all([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3)
])
.then((values) => console.log(values)); // [1, 2, 3]

✅ 18. What is async/await, and how is it used?

Async/await is a way to handle asynchronous operations in JavaScript. An async function always returns a Promise, and await pauses execution until that Promise is resolved or rejected. It makes asynchronous code cleaner and more readable, avoiding long .then() chains.

Hinglish:-

Async/Await:
Async/await JavaScript me asynchronous operations handle karne ka ek clean tarika hai. async function hamesha ek Promise return karta hai, aur await execution ko tab tak pause karta hai jab tak Promise resolve ya reject na ho jaye. Isse code zyada readable ban jata hai aur long .then() chains avoid ho jati hain.

OR

async makes a function that promises to do something later.

await tells the code to wait for that promise to finish before continuing.

OR

You use async to create a function that can run in the background. Inside that function, you use await to pause the code on one line and wait for a task to finish before moving on to the next line.

// Arrow function with async/await
const fetchUser = async () => {
try {
const res = await fetch("https://dummyjson.com");
const data = await res.json();
console.log(data); // Success
} catch (err) {
console.error("Error:", err); // Error handling
}
};

fetchUser();

✅ 19. What is the diffrence between promise and async/await ?

👉 Line: Async/Await is just syntactic sugar over Promises, making async code more readable.

Hinglish:-

Async/Await:
Async/await Promises ka hi ek syntactic sugar hai jo asynchronous code ko zyada readable aur easy banata hai.

// Promise
getData().then(res => console.log(res));

// Async/Await
async function fn() {
const res = await getData();
console.log(res);
}

✅ 20. What is the garbage collection ?

👉 Line: JavaScript automatically removes unused memory using garbage collection.

Hinglish:-

JavaScript automatically unused memory ko remove karta hai using garbage collection.

let obj = { name: "Rahul" };
obj = null; // eligible for GC

✅ 21. What is the React Reconciliation ?

👉 Line: React updates UI efficiently by comparing Virtual DOM (diffing).

Hinglish:-

React Virtual DOM ko compare (diffing) karke UI ko efficiently update karta hai.

setState({ name: "Rahul" }); // only changed part updates

✅ 22. What is the Error Boundary ?

👉 Line: Error Boundaries catch runtime errors in React components.

Hinglish:-

Error Boundaries React me runtime errors ko catch karte hain components ke andar.

class EB extends React.Component {
componentDidCatch() {
console.log("Error caught");
}
render() {
return this.props.children;
}
}

✅ 23. What is the Throttling ?

👉 Line: Throttling limits function execution to once in a given time.

Hinglish:-

Throttling:
Throttling function execution ko limit karta hai, taaki wo ek fixed time interval me sirf ek baar hi execute ho.

function throttle(fn, delay) {
let last = 0;
return () => {
if (Date.now() - last > delay) {
fn();
last = Date.now();
}
};
}

✅ 24. What is the Nullish ?

👉 Line: Returns right value only if left is null or undefined.

Hinglish:-

Returns right value only if left side null ya undefined hota hai.

let name = null ?? "Default";

✅ 25. What is the Callback Hell ?

👉 Line: Nested callbacks making code hard to read.

Hinglish:-

Nested callbacks code ko hard to read bana dete hain.

setTimeout(() => {
setTimeout(() => {
setTimeout(() => console.log("Done"), 1000);
}, 1000);
}, 1000);

✅ 26. What is the Optional Chaining ?

👉 Line: Safely access nested properties without error.

Hinglish:-

Nested properties ko safely access karna bina error ke.

user?.address?.city;

✅ 27. What is the React Rendering ?

👉 Line: Component re-renders when state or props change.

Hinglish:-

State ya props change hone par component re-render hota hai.

setCount(count + 1);

✅ 28. What is the StrictMode ?

👉 Line: Helps detect bugs in development mode.

Hinglish:-

Development mode me bugs detect karne me help karta hai.

<React.StrictMode>
<App />
</React.StrictMode>

✅ 29. What is the Suspense ?

👉 Line: Used to handle lazy loading of components.

Hinglish:-

Components ki lazy loading handle karne ke liye use hota hai.

<Suspense fallback="Loading...">
<LazyComp />
</Suspense>

✅ 30. What is the Concurrent React ?

👉 Line: Allows React to render updates in background for better performance.

Hinglish:-

React ko allow karta hai ki wo updates ko background me render kare better performance ke liye.

startTransition(() => {
setState(value);
});

✅ 31. What is the Fragment ?

👉 Line: Groups elements without adding extra DOM node.

Hinglish:-

Elements ko group karta hai bina extra DOM node add kiye.

<>
<h1>Hello</h1>
</>

✅ 32. What is the Code Splitting ?

👉 Line: Splits bundle into smaller chunks for performance.

Hinglish:-

Bundle ko smaller chunks me split karta hai performance improve karne ke liye.

const Comp = React.lazy(() => import("./Comp"));

✅ 33. What is the Microtask Queue ?

👉 Line: Promise callbacks execute in microtask queue before macrotasks.

Hinglish:-

Promise callbacks microtask queue me execute hote hain, macrotasks se pehle.

Promise.resolve().then(() => console.log("Microtask"));

✅ 34. What is the Event Bubbling ?

👉 Line: Event flows from child to parent.

Hinglish:-

Event child se parent ki taraf flow hota hai.

div.addEventListener("click", () => console.log("parent"));
button.addEventListener("click", () => console.log("child"));

✅ 35. What is the querySelector ?

👉 Line: Selects first matching DOM element.

Hinglish:-

First matching DOM element ko select karta hai.

document.querySelector(".box");

✅ 36. What is the addEventListener ?

👉 Line: Attaches event handler to element.

Hinglish:-

Element par event handler attach karta hai.

btn.addEventListener("click", () => console.log("clicked"));

✅ 37. What is the Strict Mode (JS) ?

👉 Line: Enables stricter parsing and error handling.

Hinglish:-

Stricter parsing aur error handling enable karta hai.

"use strict";
x = 10; // error

✅ 38. What are arrays in JavaScript?

Array is a collection of data in JavaScript. It can store multiple values like numbers, strings, objects, or even other arrays in a single variable.

Hinglish:-

Get Rahul Jingar’s stories in your inbox

Join Medium for free to get updates from this writer.

Array JavaScript me data ka collection hota hai. Ye ek single variable me multiple values store kar sakta hai jaise numbers, strings, objects ya even other arrays.

// Array with multiple types of values
let myArray = [42, "Hello", true, { name: "Rahul" }, [1, 2, 3]];

// Accessing elements
console.log(myArray[0]); // 42
console.log(myArray[1]); // "Hello"
console.log(myArray[3].name); // "Rahul"
console.log(myArray[4]); // [1, 2, 3]

✅ 39. How do you iterate over an array?

There are several ways to loop through an array:

const arr = [1, 2, 3];

// 1. standard for loop
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}

// 2. for...of loop (Modern and clean)
for (let num of arr) {
console.log(num);
}

// 3. forEach method (Built-in array method)
arr.forEach((item) => console.log(item));

// 4. for...in loop (not recommended for arrays, better for objects)
for (let index in arr) {
console.log(arr[index]);
}

✅ 40. What are some common array methods?

🔹 Mutating methods:

  • push() – adds to end
  • pop() – removes from end
  • shift() – removes from start
  • unshift() – adds to start
  • splice() – remove/replace/insert at index
  • 🔹 Non-mutating methods:
  • slice(start, end) – returns shallow copy
  • map() – transforms each element
  • filter() – returns elements that meet condition
  • reduce() – reduces to single value
  • find() – returns first match
  • includes() – checks existence
const nums = [1, 2, 3, 4, 5];

const doubled = nums.map(n => n * 2); // [2, 4, 6, 8, 10]
const evens = nums.filter(n => n % 2 === 0); // [2, 4]
const sum = nums.reduce((a, b) => a + b); // 15

✅ 41. How do you handle errors in JavaScript?

JavaScript provides two main ways to handle errors: try…catch and .then().catch(). try…catch is used for synchronous code and is simple to use. .then().catch() is used for Promises in asynchronous code and allows handling errors effectively in async operations.

Hinglish:-

JavaScript me errors handle karne ke do main tareeke hote hain: try…catch aur .then().catch(). try…catch synchronous code ke liye use hota hai aur simple hota hai, jabki .then().catch() Promises ke saath asynchronous code me use hota hai aur async operations me errors handle karne ke liye effective hota hai.

Synchronous:-

try {
let result = riskyOperation();
console.log(result);
} catch (error) {
console.error("Error:", error.message);
}

Asynchronous:-

fetch("https://api.example.com")
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error.message));

✅ 42. What is the difference between try…catch and Promise error handling?

try...catch handles errors in synchronous code, while Promise .catch() is used to handle errors in asynchronous code.

Hinglish:-

try...catch synchronous code me errors handle karta hai, jabki Promise .catch() asynchronous code me errors handle karta hai.

async function fetchData() {
try {
const res = await fetch("invalid-url");
} catch (err) {
console.error("Caught error:", err);
}
}

✅ 43. What are template literals, and how do you use them?

Template literals use backticks (`) and allow:

  • Multiline strings
  • Embedded expressions using ${}
const name = "Rahul";
const msg = `Hello, ${name}!`; // "Hello, Rahul!"

✅ 44. Explain destructuring assignment.

Destructuring is a way to unpack values from arrays or objects into variables.

Hinglish:-

Destructuring ek method hai jisse hum arrays ya objects se values ko unpack karke variables me store kar sakte hain.

Array destructuring:

const [a, b] = [10, 20];
console.log(a); // 10

Object destructuring:

const user = { name: "Rahul", age: 25 };
const { name, age } = user;

console.log(name); // Rahul

✅ 45. What are arrow functions, and how do they differ from regular functions?

Arrow functions are shorter syntax for writing functions and they do not have their own this.

A regular function is a standard JavaScript function declared using the function keyword.

Hinglish:-

  • Arrow functions: Functions likhne ka short syntax hota hai aur inka apna this nahi hota.
  • Regular function: Ek normal JavaScript function hota hai jo function keyword se declare kiya jata hai.
// Regular function
function sum(a, b) {
return a + b;
}

// Arrow function (ES6)
const sum = (a, b) => a + b;

✅ 46. What are spread and rest operators?

Both use the same syntax (...) but behave differently based on context.

🔹 Spread Operator:

Used to unpack elements of an array or object.

Hinglish:-

Array ya object ke elements ko unpack karne ke liye use hota hai.

const arr = [1, 2, 3];
const newArr = [...arr, 4, 5]; // [1, 2, 3, 4, 5]

const obj1 = { a: 1, b: 2 };
const obj2 = { ...obj1, c: 3 }; // { a: 1, b: 2, c: 3 }

🔹 Rest Operator:

Used to collect remaining values into an array or object.

Hinglish:-

Bache hue values ko ek array ya object me collect karne ke liye use hota hai.

function sum(...numbers) {
return numbers.reduce((a, b) => a + b, 0);
}

sum(1, 2, 3); // 6

✅ 47. What are JavaScript modules, and why are they used?

JavaScript modules are files where you write code that can be reused in other files.

OR

javascript modules are used to like that first component is created and some parts access the another component using the first component is exported and second component used the functionality accessible 2nd componnetnt used the imported that is javascript modules

OR

JavaScript modules are separate files that use export and import to share code, making it easy to reuse the same code in different parts of a project.

OR

JavaScript modules allow you to split your code into separate files. You can export functions, objects, or variables from one file and import them into another file to reuse code efficiently.

OR

A JavaScript module is a small piece of code that can be used in different parts of your program. It helps break down big projects into smaller, manageable files, allowing you to export and import functions, objects, or variables between files.

Hinglish:-

JavaScript modules alag files hote hain jisme code ko export aur import karke reuse kiya jata hai, jisse project ko chhote aur manageable parts me divide karke efficiently reuse kar sakte hain.

// math.js
export const add = (a, b) => a + b;

// main.js
import { add } from './math.js';

console.log(add(2, 3)); // 5

✅ 48. What is the Document Object Model (DOM)?

the DOM is a tree-based structure. It allows JavaScript to access and change HTML elements. The page does not refresh automatically when you click a button; it only updates what is needed, which makes the webpage faster if used correctly.

Hinglish:-

DOM ek tree-based structure hota hai jo JavaScript ko HTML elements ko access aur change karne ki permission deta hai. Button click par poora page refresh nahi hota, sirf required part update hota hai, jisse webpage faster ban jata hai.

document.getElementById("myBtn").addEventListener("click", function() {
alert("Button clicked!");
});

✅ 49. What is the difference between == and ===?

== checks if the values are equal, but === checks both the value and the data type strictly.

Hinglish:-

== values ko compare karta hai, jabki === value ke saath data type ko bhi strictly check karta hai.

✅ 50. Explain the concept of “event loop”.

The event loop is the mechanism that allows JavaScript to perform non-blocking asynchronous operations, even though it is single-threaded.

OR
The event loop is a mechanism in JavaScript that runs synchronous code first, one by one. When the call stack is empty, it runs the asynchronous code like API calls. It helps JavaScript handle multiple tasks in a single thread.

OR

The Event Loop is a mechanism in JavaScript that handles two types of code: synchronous code and asynchronous code.

Synchronous code runs first and goes directly to the call stack, where it is executed line by line.

Asynchronous code is sent to the Web APIs.
When the call stack becomes empty, the Event Loop takes the async callbacks from the callback queue and pushes them back into the call stack to execute.

This whole process is called the Event Loop, and it helps JavaScript run multiple tasks even though it is single-threaded.

Hinglish:-

Event Loop JavaScript ka ek mechanism hai jo synchronous code ko pehle execute karta hai, aur asynchronous tasks ko Web APIs me handle karta hai. Jab call stack empty hota hai, tab Event Loop callback queue se async code ko uthakar call stack me bhej deta hai, jisse JavaScript single-threaded hote hue bhi multiple tasks handle kar sakta hai.

How it works:

1. Executes code from the call stack

2. Handles asynchronous tasks via callback queue (like setTimeout, Promises, etc.)

3. The event loop checks if the call stack is empty, then pushes queued tasks to the stack.

console.log("Start");

setTimeout(() => {
console.log("Timeout");
}, 0);

console.log("End");

// Output:
// Start
// End
// Timeout

✅ 51. What is debouncing?

Debouncing is a technique that runs a function after a small delay.

✅ Example use case: A search bar should only make API calls after the user stops typing.

OR

Debouncing is a technique that makes a function run only after the user stops doing an action for a short time.

OR

Debouncing is a technique in which when a user types in a search bar, the function does not run immediately.
The function runs only after the user stops typing for a short time.

Hinglish:-

Debouncing:
Debouncing ek technique hai jisme function tab run hota hai jab user kisi action ko karna band kar deta hai kuch time ke liye, jaise search bar me typing stop hone ke baad API call hona.

function debounce(func, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => func.apply(this, args), delay);
};
}

const handleSearch = debounce(() => {
console.log("API Call");
}, 300);

✅ 52. What are higher-order functions?

A higher-order function is a function that takes another function as an argument or returns a function.

Hinglish:-

Higher-order function ek aisa function hota hai jo dusre function ko argument ke roop me leta hai ya fir ek function return karta hai.

function greet(name) {
return function(message) {
console.log(`${message}, ${name}`);
};
}

const greetRahul = greet("Rahul");
greetRahul("Good Morning"); // Good Morning, Rahul

✅ 53. What is the difference between call(), apply(), and bind()?

🔹 call():

Invokes a function immediately, with a given this value and arguments passed individually.

Hinglish:-

Ek function ko immediately call karta hai, jisme this value aur arguments individually pass kiye jate hain.

🔹 apply():

Invokes a function immediately, with a given this value and arguments passed as an array.

Hinglish:-

Ek function ko immediately call karta hai, jisme this value aur arguments ek array ke form me pass kiye jate hain.

🔹 bind():

Returns a new function with a given this value and optional arguments, but does not execute it immediately.

Hinglish:-

Ek naya function return karta hai jisme this value aur optional arguments bind hote hain, lekin ye function immediately execute nahi hota.

OR

  • call() → Calls the function immediately with this and arguments passed individually.
  • apply() → Calls the function immediately with this and arguments passed as an array.
  • bind() → Returns a new function with this fixed, can be called later.
function sayHello(greeting) {
console.log(`${greeting}, ${this.name}`);
}

const person = { name: "Rahul" };

// Using call
sayHello.call(person, "Hi"); // Hi, Rahul

// Using apply
sayHello.apply(person, ["Hello"]); // Hello, Rahul

// Using bind
const boundFn = sayHello.bind(person);
boundFn("Hey"); // Hey, Rahul

✅ 54. What is the difference between setTimeout and setInterval?

MethodDescription:-

setTimeoutRuns a function once after delaysetIntervalRuns a function repeatedly at intervals

Hinglish:-

setTimeout: Delay ke baad ek baar function run karta hai.
setInterval: Fixed interval par function repeatedly run karta rehta hai.

setTimeout(() => {
console.log("Runs once after 1 sec");
}, 1000);

setInterval(() => {
console.log("Runs every 2 seconds");
}, 2000);

✅ 55. What are symbols in JavaScript?

Symbol is a primitive data type introduced in ES6. It represents a unique identifier.

Hinglish:-

Symbol ES6 me introduce hua ek primitive data type hai jo ek unique identifier represent karta hai.

const sym1 = Symbol("id");
const sym2 = Symbol("id");

console.log(sym1 === sym2); // false (unique)

✅ 56. What are pure functions?

A pure function:

  • Always returns the same output for the same input
  • Has no side effects (does not modify external state)

Hinglish:-

Pure function:
Same input par hamesha same output return karta hai aur koi side effect nahi hota (external state ko modify nahi karta).

// Pure
function add(a, b) {
return a + b;
}

// Not pure
let x = 10;
function impureAdd(a) {
x += a;
return x;
}

✅ 57. What is currying, and why is it useful?

Currying is a technique where a function with multiple arguments is converted into a sequence of functions that each take one argument.

OR

Currying is a technique where a function takes one argument at a time and returns a new function for the next argument.

Hinglish:-

Currying ek technique hai jisme multiple arguments wale function ko aise functions ki series me convert kiya jata hai jo ek time par sirf ek argument lete hain.

function add(a) {
return function(b) {
return a + b;
};
}

console.log(add(2)(3)); // 5

✅ Currying is useful for:

  • Function reuse
  • Partial application
  • Code readability

✅ 58. What are JavaScript frameworks/libraries?

JavaScript frameworks/libraries are tools that help build apps faster and cleaner.

Libraries (help you with specific tasks):

  • jQuery
  • Lodash
  • Chart.js

Frameworks (provide structure and tools):

  • React (library, but often used like a framework)
  • Vue.js
  • Angular
  • Next.js (React-based framework)
  • Node.js (for backend)

✅ 59. Explain the concept of object-oriented programming (OOP) in JavaScript.

OOP in JavaScript uses objects to model real-world entities. Key concepts:

  • Classes — Blueprints for creating objects
  • Objects — Instances of classes
  • Encapsulation — Bundling data with methods
  • Inheritance — Reuse properties/methods from another class
  • Polymorphism — Same method behaves differently in different objects
class Animal {
speak() {
console.log("Animal speaks");
}
}

class Dog extends Animal {
speak() {
console.log("Dog barks");
}
}

const pet = new Dog();
pet.speak(); // Dog barks

✅ 60. What is a regular expression?

A regular expression (RegEx) is a pattern used to match character combinations in strings.

Hinglish:-

Regular expression (RegEx) ek pattern hota hai jo strings ke andar character combinations ko match karne ke liye use hota hai.

const regex = /hello/i;
console.log(regex.test("Hello World")); // true

✅ 61. What is the difference between strict mode and non-strict mode in JavaScript?

🔹 Strict Mode

Strict mode is a way to run JavaScript with more rules. It makes your code safer by stopping mistakes that JavaScript normally allows.

Hinglish:-

Strict mode JavaScript ko zyada strict rules ke saath run karne ka ek way hai. Ye code ko safer banata hai aur jo mistakes JavaScript normally allow karta hai unko stop karta hai.

"use strict";

x = 10; // ❌ Error: x is not defined

🔹 Non-Strict Mode (Default Mode)

Non-strict mode is the default way JavaScript runs. It is more flexible but also more risky, because it does not stop many mistakes.

Hinglish:-

Non-strict mode JavaScript ka default mode hota hai. Ye zyada flexible hota hai, lekin risky bhi hota hai kyunki ye kai mistakes ko stop nahi karta.

x = 10; // ✅ Allowed, becomes a global variable
console.log(x); // 10

OR

Strict mode has stricter rules and shows more errors, while non-strict mode is more relaxed and allows unsafe code.

✅ 62. What is a constructor function?

A constructor function is used to create multiple objects with the same structure.

Hinglish:-

Constructor function ek aisa function hota hai jo same structure wale multiple objects create karne ke liye use hota hai.

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

const rahul = new Person("Rahul", 25);

✅ 63. How do you implement inheritance in JavaScript?

There are two ways:

a) Using Prototypes:

function Animal() {
this.sound = "Generic sound";
}

Animal.prototype.makeSound = function () {
console.log(this.sound);
};

function Dog() {
Animal.call(this);
this.sound = "Bark";
}

Dog.prototype = Object.create(Animal.prototype);

const pet = new Dog();
pet.makeSound(); // Bark

b) Using Classes (ES6):

class Animal {
speak() {
console.log("Animal speaks");
}
}

class Dog extends Animal {
speak() {
console.log("Dog barks");
}
}

✅ 64. Explain the concept of polymorphism in JavaScript.

Polymorphism means many forms — the same method behaves differently based on the object calling it.

Hinglish:-

Polymorphism ka matlab “many forms” hota hai — same method different objects ke according alag-alag tarike se behave karta hai.

class Animal {
speak() {
console.log("Animal sound");
}
}

class Cat extends Animal {
speak() {
console.log("Meow");
}
}

class Dog extends Animal {
speak() {
console.log("Bark");
}
}

const animals = [new Dog(), new Cat()];
animals.forEach(a => a.speak());
// Bark
// Meow

✅ 65. What is the difference between prototype-based inheritance and class-based inheritance?

🔹 Prototype-based inheritance:

Inheritance means that if an object does not have a property, it checks its prototype to find it.

🔹 Class-based inheritance:

In class-based inheritance, a child is created using the same blueprint as the parent.

✅ 66. What is the diffrence between shallow copy and deep copy?

Shallow Copy:
A shallow copy copies only the first level of an object. If the object has nested objects, they still share the same reference.

Hinglish:-

Shallow copy sirf object ka first level copy karta hai. Agar object ke andar nested objects hote hain, to unka reference same rehta hai.

Deep Copy:
A deep copy copies all levels of an object. The new object is completely separate from the original.

Hinglish:-

Deep copy object ke sabhi levels ko copy karta hai. Naya object original se completely independent hota hai.

OR
Shallow copy copies only the outer data, so inside parts are still connected; deep copy copies everything, so all parts are separate.

Hinglish:-

Shallow copy sirf outer data ko copy karta hai, isliye inner parts same reference share karte hain; deep copy sab kuch copy karta hai, isliye saare parts completely separate hote hain.

OR

Shallow copy copies only the top part and inner parts stay connected, while deep copy copies everything and inner parts are separate.

Hinglish:-

Shallow copy sirf top level copy karta hai aur inner parts connected rehte hain, jabki deep copy sab kuch copy karta hai aur inner parts separate ho jate hain.

✅ 67. What is the diffrence between localStorage and SessionStorege?

Local Storage:
Local storage does not delete the data when you close the browser or shut down the system.
It can store around 5MB to 10MB of data.

Hinglish:-

Local Storage:
Local storage browser close ya system shutdown hone ke baad bhi data delete nahi karta. Isme approx 5MB se 10MB tak data store kiya ja sakta hai.

Session Storage:
Session storage deletes the data when you close the browser tab or window.
It can store up to 5MB of data.

Hinglish:-

Session Storage:
Session storage tab ya window close hone par data delete kar deta hai. Isme approx 5MB tak data store kiya ja sakta hai.

✅ 68. What is the diffrence between json.parse() and json.stringify()?

  • JSON.stringify converts an object into a string.
  • JSON.parse converts a string into an object.

✅69. Difference Between clear() and remove() in JavaScript

✔ remove() deletes a specific element or item.

✔ clear() removes ALL items or content.

✅70. What is Prototypes?

A prototype is an object that every JavaScript object uses as a helper.
If your object does not have a property or method, JavaScript checks its prototype to find it.

Hinglish:-

Prototype ek object hota hai jo JavaScript me har object ke liye helper ki tarah kaam karta hai. Agar kisi object me property ya method nahi milti, to JavaScript usko prototype me check karta hai.

✅71. What is recursive function?

A recursive function is a function that calls itself until it needs to stop.

Hinglish:-

Recursive function ek aisa function hota hai jo khud ko call karta rehta hai jab tak koi stopping condition (base condition) na aa jaye.

function printNumber(n) {
if (n > 5) {
return; // stop
}

console.log(n); // print number

printNumber(n + 1); // call next number
}

printNumber(1);

--

--