Learning Callbacks & forEach in JavaScript with Siva Kumar

🌱 Day 19 of My MERN Stack Journey at DevGnan Under the guidance of Siva Kumar sir Today’s Learning – Callbacks & forEach in JavaScript Today, I practiced callback functions and understood how forEach works internally in JavaScript. I learned that a callback function is a function that is passed as an argument and executed later by another function. In my example, I passed a function into forEach, and that function was executed for each item in the array. One important learning was that forEach always returns undefined. Because of this: We should not expect a return value from forEach. If we want output, we should use console.log inside the callback. Logging forEach() directly will always give undefined. I also learned the difference between passing a function and calling a function: Passing result → correct (callback runs at the right time) Calling result() → wrong (function runs immediately) → undefine This practice helped me understand why my output was undefined, how callbacks are executed, and how JavaScript handles functions inside array methods. Small concepts, but very important for writing clean and correct JavaScript 💻✨ GitHub: https://lnkd.in/gfTEMgsr #DevgNan #Day19 #JavaScript #LearningJourney #WebDevelopment #CareerGrowth

  • text

To view or add a comment, sign in

Explore content categories