0% found this document useful (0 votes)
2 views

JS-3

The document explains the differences between 'let', 'var', and 'const' in JavaScript, highlighting their scope, reassignability, and hoisting behavior. It also covers concepts like hoisting, callbacks, ES6 features, and the differences between array.map and array.filter methods. Additionally, it discusses how to find the length of an object, the states of promises, and the advantages of using promises over callbacks, along with the benefits of async and await syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JS-3

The document explains the differences between 'let', 'var', and 'const' in JavaScript, highlighting their scope, reassignability, and hoisting behavior. It also covers concepts like hoisting, callbacks, ES6 features, and the differences between array.map and array.filter methods. Additionally, it discusses how to find the length of an object, the states of promises, and the advantages of using promises over callbacks, along with the benefits of async and await syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1: Difference between let, var, and const

• let:
o Block-scoped: sirf us block ke andar valid hai jahan yeh declare hua hai.
o Reassign ho sakta hai: variable ki value badli ja sakti hai.
o Hoisting ke time pe initialize nahi hota.
• var:
o Function-scoped: puri function ke andar valid hai jahan yeh declare hua hai.
o Reassign ho sakta hai.
o Hoisting ke time pe undefined se initialize hota hai.
• const:
o Block-scoped: sirf us block ke andar valid hai jahan yeh declare hua hai.
o Reassign nahi ho sakta: variable ki value fix rahti hai, mutate kiya ja sakta hai
agar yeh object ya array hai.
o Hoisting ke time pe initialize nahi hota.

Question 2: Hoisting, Callbacks, ES6 Features

• Hoisting:
o JavaScript ka behavior jahan declarations ko apne scope ke top pe move kiya
jata hai.
o var declarations ko top pe move kiya jata hai aur unhe undefined se initialize
kiya jata hai.
o let aur const declarations ko bhi hoist kiya jata hai, lekin unhe initialize nahi
kiya jata.
• Callbacks:
o Ek function jo dusre function ko argument ke roop mein pass kiya jata hai.
o Yeh asynchronous operations ke complete hone par call kiya jata hai.
• ES6 Features:
o Arrow functions
o Template literals
o Destructuring assignment
o Default parameters
o Rest and spread operators
o let and const
o Classes
o Promises
o Modules

Question 3: Difference between array.map and array.filter

• array.map:
o Har element pe ek function apply karta hai aur results ka naya array return
karta hai.
o Original array ko modify nahi karta.
• array.filter:
o Har element pe ek test function apply karta hai aur sirf un elements ko return
karta hai jo test pass karte hain.
o Original array ko modify nahi karta.
Question 4: How to find the length of an object

Object ki length (number of properties) ko find karne ke liye Object.keys() method ka use
kiya jata hai:

javascript
Copy code
let obj = { a: 1, b: 2, c: 3 };
console.log(Object.keys(obj).length); // Output: 3

Question 5: What are promises? 3 states of promises.

Promises JavaScript mein ek object hain jo asynchronous operation ka result represent karte
hain. Promises ke 3 states hote hain:

1. Pending: Initial state, neither fulfilled nor rejected.


2. Fulfilled: Operation successfully complete hua aur promise ne result return kiya.
3. Rejected: Operation fail hua aur promise ne error return kiya.

Question 6: Why do we use promises over callbacks and why use await and async?

• Promises over Callbacks:


o Better readability and manageability.
o Avoid callback hell (nested callbacks).
o Easier error handling using .catch().
• async and await:
o Synchronous-like code for handling asynchronous operations.
o Better readability and easier to write and understand.
o Simplifies chaining of promises.

You might also like