Shalow Copy: Shalow copy upper se copy kr
leta hn but deep copy nahi kr pata
example:
use spread operator {...obj} to get deep copy from spread operator but it copy objects not deep and nested object
Deep Copy:Deep copy deep tk objects ko copy kr leta hn means proper copy krna nested object and array ko deep copy krna.
ye niche ek method hn deep copy kar raha hn jo ke just practice ke liye hn, ye ham Interview me nahi batynge
ye niche ek recursive function hn jo ke deep copy kr raha hn object ki or arrays ki agr koi premitive data dynge to wo return kr dy ga
PromisesA Promise ek object hai jo asynchronous code ke result ko manage karta
hai.
Yeh 3 states me ho sakta hai:
How to Use Promises?
1) Promise.all()
2) Promise.allSettled()
Example:
Output:
3) Promise.race()
Example:
4) Promise.any() (ES2021)
Example:
5) Promise.resolve()
Example:
6) Promise.reject()
Example:
function inside object is called Methods
Spread operator ek modern JavaScript feature hai jo ek array ya object ke elements ko alag-alag (spread) karne ke liye use hota hai.
Example:
Rest operator ka use multiple elements ko ek array ya object ke andar "collect" karne ke liye hota hai. Ye zyada tar destructuring aur functions ke arguments handle karne ke liye use hota hai.
Example:
Spread Operator:
Rest Operator:
Destructuring in JavaScriptDestructuring ek JavaScript syntax hai jo arrays aur objects ke elements ko extract (nikalne) aur unhe alag variables mein store karne ke liye use hoti hai. Iska kaam hai code ko concise aur readable banana.
Types of Destructuring:
1) Array Destructuring
Array destructuring ka use array ke elements ko alag variables mein extract karne ke liye hota hai.
2) Object Destructuring
Array destructuring ka use array ke elements ko alag variables mein extract karne ke liye hota hai.
Conclusion Destructuring ek powerful aur modern JavaScript feature hai jo code ko concise, readable, aur manageable banata hai. Ye har modern JavaScript developer ka tool hai, especially jab aapko APIs, React, ya complex data structures ke sath kaam karna ho.