Programming concepts और सीखने के लिए आप
MDN Web Docs देख सकते हैं।
Example: Fetch data from API
Example: API से data fetch करना
3. Closures & Scope
Closures allow a function to remember variables from its outer scope even after the outer function has executed. Useful for data encapsulation and private variables.
Closures function ko outer scope ke variables yaad rakhne dete hain, chahe outer function execute ho chuka ho. Data encapsulation aur private variables ke liye useful.
Inner function has access to outer function variables.
Useful to create private counters or encapsulated logic.
Closures preserve state between function calls.
Inner function ko outer function ke variables access karne ki permission hoti hai.
Private counters ya encapsulated logic banane ke liye useful.
Closures function calls ke beech state preserve karte hain.
Programming concepts और सीखने के लिए आप
MDN Web Docs देख सकते हैं।
Example: Private counter using closure
Example: Closure se private counter
4. Higher-Order Functions
Higher-order functions either take functions as arguments or return functions. Useful for map, filter, reduce, and functional programming.
Higher-order functions ya to functions ko arguments ke roop me lete hain ya function return karte hain. Map, filter, reduce aur functional programming ke liye useful.
Functions can be passed as parameters.
Functions can return another function.
Encourages reusable and modular code.
Functions ko parameters ke roop me pass kar sakte hain.
Functions doosre functions return kar sakte hain.
Reusable aur modular code likhne me madad.
Diagram: Higher-Order Function Flow
Example: Using map to double numbers
Example: Map function se numbers double करना
5. Pure vs Impure Functions
Pure functions always return the same output for same inputs and have no side effects. Impure functions may change external state or depend on external variables.
Pure functions same inputs ke liye hamesha same output dete hain aur koi side effects nahi rakhte. Impure functions external state change kar sakte hain ya external variables pe depend karte hain.
Pure functions are predictable and testable.
Impure functions are harder to debug.
Encourage functional programming for maintainable code.
Pure functions predictable aur testable hote hain.
Impure functions debug karna mushkil hota hai.
Maintainable code ke liye functional programming encourage karein.