Today I explored two powerful JavaScript concepts: Higher Order Functions (HOF) and Closures. 🔹 Higher Order Functions (HOF) A function that takes another function as an argument or returns a function. Example: function greet(name){ return "Hello " + name; } function processUser(fn){ console.log(fn("Praful")); } processUser(greet); Functions like map(), filter(), reduce() are common examples of HOF. 🔹 Closures A closure happens when a function remembers variables from its outer scope even after the outer function has finished executing. Example: function counter(){ let count = 0; return function(){ count++; console.log(count); } } const inc = counter(); inc(); // 1 inc(); // 2 The inner function still remembers the variable count because of closures. Understanding these concepts helps write clean, modular, and powerful JavaScript code. Thanks to Sheryians Coding School for explaining these concepts so clearly 🚀 Day 7 of my 21 Days JavaScript Concept Challenge ✅ #JavaScript #WebDevelopment #FrontendDeveloper #LearningInPublic #CodingJourney #SheryiansCodingSchool
Higher Order Functions & Closures in JavaScript Explained
More Relevant Posts
-
🎯 JavaScript Learning Challenge – Day 4/20 🔢 Day 4 Project: Counter App Today I built a simple Counter Application using JavaScript. The app allows users to increase and decrease a number with button clicks, which helped me understand how state changes work in a basic JavaScript application. 💡 Concepts I practiced today: • Selecting elements using querySelector() • Handling user interactions with addEventListener() • Updating values dynamically in the DOM • Managing state using variables in JavaScript This project may look simple, but it’s one of the fundamental exercises for understanding event-driven programming in JavaScript. 📅 Day 4/20 completed — small projects, consistent progress. #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #mernstack #20daysChallenge #consistency
To view or add a comment, sign in
-
🚀 Day 86 of My #100DaysOfCode Challenge Today I discovered a lesser-known feature in JavaScript — Symbols. Most developers work with object keys using strings, but JavaScript also provides another unique type called Symbol. A Symbol creates a unique and hidden property key that cannot accidentally conflict with other keys. Example const id = Symbol("id"); const user = { name: "Tejal", [id]: 12345 }; console.log(user.name); // Tejal console.log(user[id]); // 12345 Why Symbols are interesting • Every Symbol is unique • Helps create hidden object properties • Prevents accidental property overwriting • Often used internally in libraries and frameworks Even if two symbols have the same description, they are still different. const a = Symbol("key"); const b = Symbol("key"); console.log(a === b); // false Learning about features like Symbols helps me understand how JavaScript works behind the scenes and how large applications manage object data safely. Exploring deeper concepts every day. 💻✨ #Day86 #100DaysOfCode #JavaScript #WebDevelopment #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🧠 JavaScript Closures — The Concept That Feels Confusing (Until It Clicks) Closures are not magic… they’re just how JavaScript remembers things. 👉 Definition: A closure is when a function “remembers” variables from its outer scope even after that outer function has finished executing. 💻 Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 counter(); // 3 🤯 Why this works? Even though "outer()" is done, the "inner()" function still has access to "count". That’s a closure. 🔥 Real Use Cases: ✔ Data privacy (like private variables) ✔ Creating counters ✔ Maintaining state in functions ✔ Used heavily in React (hooks concept) 💡 Simple Way to Remember: 👉 “A function + its remembered environment = Closure” I learned this concept from 👉 Sheryians Coding School #javascript #frontend #webdevelopment #coding #developers #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Revising JavaScript by Building 5 Mini Projects Instead of just re-reading theory, I decided to revise JavaScript the practical way — by building small apps from scratch. Each mini project helped reinforce core concepts and turn knowledge into real experience. Here’s what I built 👇 🔀 1. Clone List (DOM Manipulation) An interactive app where clicking an item clones it and moves it to another list — and it can also move back. Built using cloneNode(), event delegation, and appendChild(). 🎲 2. Random Array Generator Enter a min and max value to instantly generate a random 10-element array. Includes input validation and uses Math.random() and Math.floor(). ⏱️ 3. Stopwatch A clean stopwatch with Start / Stop / Reset controls. Built with setInterval, time formatting (HH:MM:SS), and padStart() to ensure consistent display. ✅ 4. To-Do List App A simple but powerful task manager with: • Add, Edit, and Delete tasks • Mark tasks complete with strikethrough • Duplicate detection with toast notifications • LocalStorage persistence so tasks survive page refresh 🌍 5. Country Neighbor Finder (Fetch API) Search for any country and fetch live data from a REST API including: • Flag, region, population, language, and currency • Neighboring country loaded using chained .then() promises • Graceful handling for countries with no borders 💡 Concepts practiced: DOM Manipulation · Event Delegation · setInterval / clearInterval · LocalStorage · Fetch API · Promises & .then() · Array methods · cloneNode() · Math.random() Every mini project is a reminder that the best way to learn programming is by building things — even small ones. If you're learning JavaScript, try building tiny projects like these. They make a huge difference. 💪 #JavaScript #Frontend #WebDevelopment #Programming #Coding #Developers #LearningInPublic #100DaysOfCode #MiniProjects #DOM #FetchAPI #Promises #LocalStorage #ITI #ITICoders
To view or add a comment, sign in
-
🚀 30 Days of JavaScript – Day 9 Continuing my journey to improve my JavaScript logical thinking by building small interactive programs every day. 💡 Today’s Mini Project: Word Scramble Game 🧩 In this game, the program selects a random word, scrambles its letters, and the user must guess the correct word. If the guess is wrong, the program asks the user to try again. After the correct answer, the user can choose to play again with a new word. 🧠 Concepts Used: Arrays Math.random() split(), sort(), join() while loop Conditional logic 📌 Example Scrambled Word → gcodni Correct Answer → coding 🎥 Demo below 👇 Full source code in the First comment. #JavaScript #WebDevelopment #CodingJourney #ProblemSolving #LearningJavaScript #30DaysOfCode
To view or add a comment, sign in
-
Mastering Callbacks in JavaScript – The Foundation of Async Programming If you're learning JavaScript, understanding callbacks is a game-changer. 💡 Functions in JS are first-class citizens — meaning you can pass them around just like data. 👉 That’s where callbacks come in. From simple synchronous execution to real-world async scenarios like timers, events, and API calls — callbacks power it all. But there’s a twist… 😵💫 As your logic grows, you may hit the infamous Callback Hell (Pyramid of Doom) — deeply nested, hard-to-read code. ⚠️ Why it happens: • Each async task depends on the previous one • Callbacks keep stacking • Readability takes a hit ✅ Modern solutions: • Promises • Async/Await These make your code cleaner, more readable, and easier to maintain. 📌 Key takeaway: Callbacks are not outdated — they are the foundation. Master them, and everything else (Promises, Async/Await) becomes easier. #JavaScript #WebDevelopment #Frontend #AsyncProgramming #Coding #100DaysOfCode #DevTips #LearnToCode #chaicode Chai Aur Code
To view or add a comment, sign in
-
-
🚀 Day 81 of My #100DaysOfCode Journey Today I explored an interesting JavaScript concept that many beginners overlook — Debouncing. When users type in a search box or resize a browser window, events can trigger hundreds of times in a few seconds. Running heavy code every time can slow down the application. This is where Debouncing helps. 👉 Debouncing ensures a function runs only after a certain delay, and only once the user stops triggering the event. Example function debounce(func, delay) { let timer; return function (...args) { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, args); }, delay); }; } function searchData() { console.log("Searching..."); } const optimizedSearch = debounce(searchData, 500); Why this matters • Improves website performance • Reduces unnecessary API calls • Creates smoother user experience This small concept is actually used in real-world applications like search bars, auto-save features, and input validations. Every day I discover that JavaScript has many small concepts that make a big difference in real projects. Slowly learning, building, and improving every day. 💻 #Day81 #100DaysOfCode #JavaScript #WebDevelopment #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
I used to ignore call(), apply(), and bind() in JavaScript because they always felt confusing and not very useful. But recently, I understood them in the simplest way possible. The whole concept is actually about just one thing "this". In JavaScript, 'this' tells you which object the function is using. And sometimes, when you pass a function somewhere else, it forgets its original object. For example, if you have a function inside an object and you call it normally, everything works fine. But if you store that function in a variable or pass it as a callback, it can lose its connection with the object. That is where the problem starts. This is exactly where call(), apply(), and bind() help. call() and apply() are used when you want to run a function and manually tell it which object to use. bind() is slightly different. It does not run the function immediately. It gives you a new function where 'this' is permanently fixed, so you can use it later without worrying. I faced this while attaching a function to a button click. The function stopped working properly because this was pointing to something else. After using bind(), it started working perfectly. The best way to remember this is simple. call() and apply() run the function immediately with the correct object. bind() prepares a function for later with the correct object. That’s it. No need to overcomplicate it. #JavaScript #WebDevelopment #Frontend #LearningInPublic #CodingJourney #100DaysOfCode Sheryians Coding School
To view or add a comment, sign in
-
-
Day 4 of My JavaScript Learning Journey Today I learned about one of the most important data structures in JavaScript — Arrays. An Array is used to store multiple values in a single variable, which makes managing lists of data much easier. 🔹 Key things I learned today: • What an array is and how it stores multiple values • How to access array elements using indexes • Important array properties like length • Useful array methods such as push(), pop(), shift(), unshift(), slice(), and splice() 💡 Example use cases of arrays: Storing a list of users Managing product lists in an e-commerce website Handling tasks in a to-do app #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #LearnInPublic #100DaysOfCode
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development