function greet(name, callback) {
console.log("Hello " + name);
callback();
}
function done() {
console.log("Completed");
}• greet("Deepak", done);
Output:
• Hello Deepak
• Completed
🚀 14. Higher Order Functions
Higher Order Functions -> functions that:
• Accept functions as arguments
• Return functions
Example:
function operation(callback) {
callback();
}• operation(() => {
console.log("Executed");
});
⚡ 15. Closures
Closures -> one of the most important interview topics.
A closure -> allows a function to remember variables from its outer scope.
Example:
function counter() {
let count = 0;
return function() {
count++;
console.log(count);
};
}
const increment = counter();• increment();
• increment();
Output:
• 1
• 2
🎯 16. Recursive Functions
Recursive -> a function calling itself.
Example:
function countdown(n) {
if(n === 0) {
return;
}
console.log(n);
countdown(n - 1);
}• countdown(5);
Output:
• 5
• 4
• 3
• 2
• 1
🧮 17. Practical Example — Sum of Array
function sumArray(arr) {
return arr.reduce((sum, num) => sum + num, 0);
}console.log(sumArray([1, 2, 3]));
Output:
• 6
⭐ Important Interview Topics
Focus heavily on:
• 🔥 Function Declaration
• 🔥 Function Expression
• 🔥 Arrow Functions
• 🔥 Scope
• 🔥 Closures
• 🔥 Callback Functions
• 🔥 Higher Order Functions
• 🔥 Recursion
• 🔥 Hoisting
📝 Mini Practice Questions
Easy
• ✅ Create calculator function
• ✅ Find maximum of two numbers
• ✅ Check even or odd
Medium
• ✅ Reverse string
• ✅ Find factorial
• ✅ Check palindrome
Advanced
• ✅ Implement debounce
• ✅ Implement throttle
• ✅ Create custom map() function
Double Tap ❤️ For More