🚀 Day 2 of My 30 Days of JavaScript Journey ✅ Challenge: Counter Function (LeetCode #2620) Create a function createCounter(n) that returns another function. Each time the returned function is called, it should return the current value of n and then increment it by 1 — producing outputs like (n, n+1, n+2, ...). 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gczTUyQ4 💡 Solution: https://lnkd.in/g2VVnv8u 🧠 Concept Highlighted: This problem reinforces the concept of closures — how JavaScript functions can "remember" variables from their outer scope even after the outer function has finished executing. It’s a foundational concept for mastering state management and functional programming in JS. 📘 My Takeaway: A small problem, but a powerful reminder that closures are at the heart of JavaScript. Understanding how functions preserve state paves the way for writing more efficient and modular code. Step by step, the logic becomes clearer! 💪 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #Closures
Varshini Senthil’s Post
More Relevant Posts
-
🚀 Day 4 of My 30 Days of JavaScript Journey ✅ Challenge: Create Counter Object (LeetCode #2665) Write a function createCounter(init) that returns an object with three functions: increment() → increases the value by 1 and returns it. decrement() → decreases the value by 1 and returns it. reset() → resets the value to the initial value and returns it. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gKxPxb8Y 💡 Solution: https://lnkd.in/g3jv6Nfi 🧠 Concept Highlighted: This challenge strengthens understanding of closures and object methods in JavaScript. It shows how functions can preserve and modify internal state — a key concept in building dynamic, stateful applications. #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #Closures #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 1 of My 30 Days of JavaScript Challenge 🧩 Problem: Create Hello World Function (LeetCode #2667) Write a function createHelloWorld that returns a new function which always returns "Hello World", no matter what arguments are passed. 💻 Language: JavaScript ❓ Question: https://lnkd.in/eVgQ9W87 💡Solution:https://lnkd.in/ed7AXEYr 🧠 Concept Used: JavaScript closures and higher-order functions Demonstrates how a function can return another function 📚 Takeaway: A simple yet powerful reminder that understanding function behavior and scope is key in JavaScript. Every small step builds stronger fundamentals! #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 4 of My 30 Days of JavaScript Challenge 🧩 Problem: Create Counter II (LeetCode #2665) Write a function createCounter(init) that returns an object with three functions: increment() → increases the current value by 1 and returns it decrement() → decreases the current value by 1 and returns it reset() → resets the value back to init and returns it 💻 Language: JavaScript ❓ Question: https://lnkd.in/eupkr-a3 💡 Solution: https://lnkd.in/eq3BEsn2 🧠 Concepts Used: Closures for maintaining private state across function calls Object methods to encapsulate multiple related actions State management inside functions 📚 Takeaway: This challenge reinforces closures and encapsulation — two powerful ideas that make JavaScript functions behave like real objects with memory and behavior. #Day4 #JavaScript #30DaysOfCode #LeetCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
Day 5 of #30DaysOfJavaScript: Creating My Own Filter Function from Scratch! 🎯 Today, I tackled a great exercise that challenged me to build a custom filter function without using JavaScript’s built-in .filter() method. This involved iterating over an array and using a callback function to decide which elements to keep based on truthy values. Here’s a peek at the solution I wrote: Key takeaways from this challenge: Deepened my understanding of higher-order functions and callback usage. Learned how to evaluate truthy and false values in JavaScript more effectively. Gained appreciation for the power and convenience of built-in array methods by implementing one manually. This hands-on approach is helping me grasp fundamental JavaScript concepts in detail while preparing for real-world coding challenges. Excited to keep growing and solving more problems along the way! Let’s connect and share knowledge. #JavaScript #CodingChallenge #WebDevelopment #LeetCode #ArrayMethods #LearningByBuilding #DeveloperJourney
To view or add a comment, sign in
-
-
Day 3: Deepening JavaScript Skills with Counter Function Challenge! 🚀 Today, I tackled a classic problem — creating a flexible counter object that can increment, decrement, and reset — and it really sharpened my understanding of closures and object-oriented design in JavaScript. I implemented the createCounter function to accept an initial value and return an object with three methods: increment(): increases the value by 1 and returns it decrement(): decreases the value by 1 and returns it reset(): resets the value to the initial value and returns it This exercise reinforced how closures help maintain persistent state for each counter instance, making the code both clean and efficient. Here's a quick snippet: javascript const createCounter = (init) => { let n = init; return { increment() { return ++n; }, decrement() { return --n; }, reset() { n = init; return n; } }; }; Excited to keep pushing forward on this JavaScript journey! 💪 Let’s continue learning and sharing—feel free to share your progress or ask questions below. #JavaScript #30DaysOfJS #CodingJourney #Closure #WebDevelopment #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 1 of My 30 Days of JavaScript Journey ✅ Challenge: Create Hello World Function (LeetCode #2667) Build a function createHelloWorld that returns another function which always outputs "Hello World", regardless of any arguments passed. 💻 Language Used: JavaScript ❓Problem Link: https://lnkd.in/gSnZfTN2 💡Solution: https://lnkd.in/gvjBEgRA 🧠 Concept Highlighted: This problem focuses on JavaScript closures and higher-order functions, showing how one function can return another — a key concept in mastering JS. 📘 My Takeaway: Even the simplest exercises can reinforce core JavaScript principles like function behavior and scope. Every bit of consistent practice strengthens the foundation for bigger challenges ahead! 💪 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday
To view or add a comment, sign in
-
🚀 Day 10 of My 30 Days of JavaScript Journey ✅ Challenge: Allow One Function Call (LeetCode #2666) Create a function once(fn) that ensures a given function can only be executed once. The first call should execute and return the result of fn, while all subsequent calls should return undefined. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gpX3MkFD 💡 Solution: https://lnkd.in/gAYsYP6d 🧠 Concept Highlighted: This problem focuses on closures and function state management in JavaScript. By storing state within a closure, we can control how many times a function executes — a powerful concept for optimizing performance and preventing redundant calls. #Day10 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #Closures #LearningEveryday #ProblemSolving #ES6
To view or add a comment, sign in
-
🚀 Day 3 of My 30 Days of JavaScript Challenge 🧩 Problem: Implement expect() Function (LeetCode #2704) Write a function expect that helps developers test their code. It takes a value val and returns an object with two methods: toBe(val) → returns true if both values are strictly equal (===), else throws "Not Equal" notToBe(val) → returns true if both values are not strictly equal (!==), else throws "Equal" 💻 Language: JavaScript ❓ Question: https://lnkd.in/eJcRKeme 💡 Solution: https://lnkd.in/eZY9mYHN 🧠 Concepts Used: Higher-order functions (function returning object with functions) Error handling using throw new Error() Strict equality (===) in JavaScript 📚 Takeaway: This exercise reinforces function design, object methods, and error handling — the foundation for building custom testing utilities and debugging tools in JavaScript. #Day3 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
JavaScript for 15 Days – Day 5: Functions Today, You will learn about Functions, one of the most important concepts in JavaScript. A function is basically a reusable block of code that performs a specific task. It helps you write cleaner, more organized, and less repetitive code. Example: function greet(name) { return `Hello, ${name}!`; } console.log(greet("Moussa")); // Hello, Moussa! Why functions matter: - They make your code reusable and modular. - They improve readability. - They help you manage logic step by step. JavaScript also supports arrow functions and function expressions, which you’ll explore in slides! #JavaScript #FrontendDevelopment #CodingJourney #LearnToCode #WebDevelopment #15DaysJS #DevPerDay
To view or add a comment, sign in
-
🚀 Day 10 of My 30 Days of JavaScript Challenge 🧩 Problem: Allow One Function Call (LeetCode #2666) Given a function fn, return a new function that ensures fn can only be called once. The first call returns the actual result, and every subsequent call returns undefined. 💻 Language: JavaScript 📖 Problem Link: https://lnkd.in/epnrfahZ 💡 Solution: https://lnkd.in/eGQKWkEk 🧠 Concepts Used Closures to store state (whether function is already called) Function Wrapping Higher-Order Functions 📚 Takeaway This problem is a great example of how closures preserve state between function calls — an essential concept for: Memoization API rate-limiting Event listener control #Day10 #JavaScript #30DaysOfCode #LeetCode #WebDevelopment #CodingChallenge #Closures #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
Explore related topics
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