🚀 Day 30/50 – Function Currying in JavaScript Think of Function Currying like building a relationship. You don’t propose directly 😅 First comes the “Hi Hello 👋” phase → then friendship ☕ → and finally… the proposal ❤️ In JavaScript, instead of passing all arguments at once, Function Currying lets us pass them step by step, each step returning a new function until the final output is achieved. Here’s a simple code analogy from my video: function proposeTo(crush) { return function (timeSpent) { return function (gift) { return `Dear ${crush}, after ${timeSpent} of friendship, you accepted my ${gift}! 🥰`; }; }; } console.log(proposeTo("Sizuka")("3 months")("red rose 🌹")); Each function takes one argument and returns another function — making the code modular, flexible, and easy to reuse. 👉 This is Function Currying — one argument, one step, one perfect result. 🎥 Watch the full short video here: 🔗 https://lnkd.in/g-NkeYBc --- 💡 Takeaway: Function Currying isn’t just a JavaScript trick — it’s a powerful pattern for cleaner, more composable functions that enhance reusability and maintainability in modern frontend code. --- Would love to know: 👉 What’s your favorite JavaScript concept that clicked instantly when you saw it explained simply? #javascript #frontenddevelopment #webdevelopment #coding #programming #softwareengineering #learnjavascript #100daysofjavascript #techsharingan #developers #careergrowth
Function Currying in JavaScript: A Simple Analogy
More Relevant Posts
-
Understanding this in JavaScript this — one of the most misunderstood keywords in JavaScript. It’s simple in theory… until it suddenly isn’t 😅 Here’s what makes it tricky — this depends entirely on how a function is called, not where it’s written. Its value changes with context. Let’s look at a few examples 👇 const user = { name: "Sakura", greet() { console.log(`Hello, I am ${this.name}`); }, }; user.greet(); // "Sakura" ✅ const callGreet = user.greet; callGreet(); // undefined ❌ (context lost) const boundGreet = user.greet.bind(user); boundGreet(); // "Sakura" ✅ (context fixed) Key takeaways 🧠 ✅ this refers to the object that calls the function. ✅ Lose the calling object → lose the context. ✅ Use .bind(), .call(), or .apply() to control it. ✅ Arrow functions don’t have their own this — they inherit from the parent scope. These small details often trip up developers in interviews and real-world debugging sessions. Once you understand the context flow, this becomes a lot less scary to work with. 💪 🎥 I simplified this in my Day 28/50 JS short video— check it out here 👇 👉 https://lnkd.in/gyUnzuZA #javascript #webdevelopment #frontend #backend #programming #learnjavascript #softwaredevelopment #developerslife #techsharingan #50daysofjavascript
To view or add a comment, sign in
-
*5 Things I Wish I Knew When Starting JavaScript 👨💻* Looking back, JavaScript was both exciting and confusing when I started. Here are 5 things I wish someone had told me earlier: *1. `var` is dangerous. Use `let` and `const`* – `var` is function-scoped and can lead to unexpected bugs. `let` and `const` are block-scoped and safer. *2. JavaScript is asynchronous* – Things like `setTimeout()` and `fetch()` don’t behave in a straight top-down flow. Understanding the *event loop* helps a lot. *3. Functions are first-class citizens* – You can pass functions as arguments, return them, and even store them in variables. It’s powerful once you get used to it. *4. The DOM is slow – avoid unnecessary access* – Repeated DOM queries and manipulations can hurt performance. Use `documentFragment` or batch changes when possible. *5. Don’t ignore array methods* – `map()`, `filter()`, `reduce()`, `find()`… they make code cleaner and more readable. I wish I started using them sooner. 💡 *Bonus Tip:* `console.log()` is your best friend during debugging! If you’re starting out with JS, save this. And if you're ahead in the journey — what do *you* wish you knew earlier? #JavaScript #WebDevelopment #CodingJourney #Frontend #LearnToCode #DeveloperTips
To view or add a comment, sign in
-
*5 Things I Wish I Knew When Starting JavaScript 👨💻* Looking back, JavaScript was both exciting and confusing when I started. Here are 5 things I wish someone had told me earlier: *1. var is dangerous. Use "let" and "const" "var" is function-scoped and can lead to unexpected bugs. "let" and "const" are block-scoped and safer. *2. JavaScript is asynchronous Things like "setTimeout()"and "fetch()" don’t behave in a straight top-down flow. Understanding the *event loop* helps a lot. *3. Functions are first-class citizens* – You can pass functions as arguments, return them, and even store them in variables. It’s powerful once you get used to it. *4. The DOM is slow – avoid unnecessary access* – Repeated DOM queries and manipulations can hurt performance. Use "documentFragment" or batch changes when possible. *5. Don’t ignore array methods* map(), "filter()" , "reduce()", "find()"… they make code cleaner and more readable. I wish I started using them sooner. 💡 *Bonus Tip:* "console.log()" is your best friend during debugging! If you’re starting out with JS, save this. And if you're ahead in the journey — what do *you* wish you knew earlier? #JavaScript #WebDevelopment #CodingJourney #Frontend #LearnToCode #DeveloperTips
To view or add a comment, sign in
-
Today's Topic: Promise Chaining in JavaScript In JavaScript, Promise chaining allows you to execute asynchronous tasks one after another, ensuring that each step waits for the previous one to finish. Instead of nesting callbacks (callback hell ), promises make your code cleaner and easier to maintain. Example: function step1() { return new Promise((resolve) => { setTimeout(() => { console.log("Step 1 completed ✅"); resolve(10); }, 1000); }); } function step2(value) { return new Promise((resolve) => { setTimeout(() => { console.log("Step 2 completed ✅"); resolve(value * 2); }, 1000); }); } function step3(value) { return new Promise((resolve) => { setTimeout(() => { console.log("Step 3 completed ✅"); resolve(value + 5); }, 1000); }); } // Promise Chaining step1() .then(result => step2(result)) .then(result => step3(result)) .then(finalResult => console.log("Final Result:", finalResult)) .catch(error => console.error("Error:", error)); ✅ Output (after 3 seconds): Step 1 completed ✅ Step 2 completed ✅ Step 3 completed ✅ Final Result: 25 Each .then() runs after the previous promise resolves — making async flow easy to read and manage. --- 🔖 #JavaScript #WebDevelopment #PromiseChain #AsyncProgramming #CodingTips #FrontendDevelopment #Developers #JSConcepts #CodeLearning #100DaysOfCode #WebDevCommunity
To view or add a comment, sign in
-
-
💡 Understanding var, let, and const in JavaScript — A Must for Every Developer! When writing JavaScript, knowing how variables behave is crucial for clean and bug-free code. Here’s a quick breakdown 👇 🔹 var Scope: Function-scoped Hoisted: Yes (initialized as undefined) Re-declaration: Allowed ⚠️ Can cause unexpected results due to hoisting and re-declaration. 🔹 let Scope: Block-scoped ({ }) Hoisted: Yes (but not initialized — Temporal Dead Zone) Re-declaration: ❌ Not allowed in same scope ✅ Preferred for variables that can change. 🔹 const Scope: Block-scoped Hoisted: Yes (not initialized — Temporal Dead Zone) Re-declaration / Re-assignment: ❌ Not allowed ✅ Use for constants and values that never change. 🔍 Example: { var a = 10; let b = 20; const c = 30; } console.log(a); // ✅ Works (function-scoped) console.log(b); // ❌ Error (block-scoped) console.log(c); // ❌ Error (block-scoped) 🧠 Pro tip: Always prefer let and const over var for predictable and safer code. ✨ Which one do you use most often — let or const? Let’s discuss 👇 #JavaScript #WebDevelopment #Frontend #CodingTips #ES6
To view or add a comment, sign in
-
⚙ Understanding Functions in JavaScript — The Building Blocks of Code A function in JavaScript is like a mini-program inside your main program. It allows you to reuse code, organize logic, and make your code modular. --- 💡 Definition: A function is a block of code designed to perform a particular task. You can define it once and call it multiple times. --- 🧠 Syntax: function greet(name) { console.log("Hello, " + name + "! 👋"); } greet("Kishore"); greet("Santhiya"); ✅ Output: Hello, Kishore! 👋 Hello, Santhiya! 👋 --- 🧩 Types of Functions: 1. Named Function function add(a, b) { return a + b; } 2. Anonymous Function const multiply = function(a, b) { return a * b; }; 3. Arrow Function const divide = (a, b) => a / b; --- ⚙ Why Functions Matter: ✅ Reusability ✅ Readability ✅ Easier debugging ✅ Cleaner, modular code --- 🔖 #JavaScript #WebDevelopment #FunctionsInJS #Frontend #CodingTips #JSConcepts #LearnToCode #100DaysOfCode #KishoreLearnsJS #DeveloperJourney #WebDevCommunity #CodeLearning
To view or add a comment, sign in
-
🍏 JS Daily Bite #7 🧬 JavaScript Inheritance: Understanding the Prototype Chain JavaScript's approach to inheritance is unique — and understanding it is key to mastering the language. 🚀 What is the Prototype Chain? JavaScript objects are dynamic collections of properties ("own properties"). But here's where it gets interesting: every object also has a link to a prototype object. When you try to access a property, JavaScript doesn't just look at the object itself — it searches up the prototype chain until it either finds the property or reaches the end of the chain. 🧩 🔑 Key Concepts to Know: [[Prototype]] is the internal link to an object's prototype, accessible via Object.getPrototypeOf() and Object.setPrototypeOf(). Don’t confuse obj.__proto__ with func.prototype — the latter specifies what prototype will be assigned to instances created by a constructor function. In object literals, you can use { __proto__: c } to set the prototype directly. 🧠 The “Methods” Twist: JavaScript doesn’t have methods in the traditional class-based sense. Functions are just properties that can be inherited like any other. And here's a critical detail: when an inherited function executes, this points to the inheriting object — not the prototype where the function is defined. ⚡ 💡 Why This Matters: Understanding prototypes is essential for working with JavaScript's object model, debugging inheritance issues, and leveraging modern class syntax (which is really just syntactic sugar over prototypes). 👉 Next up: Constructors — how JavaScript creates and links objects during instantiation! #JavaScript #JSDailyBite #WebDevelopment #Programming #FrontendDevelopment #SoftwareEngineering #LearnToCode #TechEducation #CodeNewbie #Developers #100DaysOfCode
To view or add a comment, sign in
-
🔥 JavaScript: When “prototype” is NOT an object 👀 We all learn early — > “Every function in JavaScript has a prototype property that is an object.” But JavaScript loves exceptions 😏 Here are some surprising cases where prototype is not an object 👇 RegExp.prototype // → /(?:)/ Array.prototype // → [] Function.prototype // → ƒ () {} Number.prototype // → Number {} String.prototype // → String {} Boolean.prototype // → Boolean {} Symbol.prototype // → Symbol {} BigInt.prototype // → BigInt {} 💡 Notice something? Some of these are functions, arrays, or even regular expressions! That’s because their prototypes are actual instances of their types, not plain objects — so that all instances inherit their core methods directly. For example: Array.prototype.push === [].push // true ✅ RegExp.prototype.test === /abc/.test // true ✅ So next time you assume prototype is always {}, remember — JS is full of living examples 😉 --- 💬 Have you ever found a weird prototype behavior while debugging? Drop it in the comments — let’s break more JS myths together! ⚙️ #JavaScript #WebDevelopment #LearningEveryday #Frontend
To view or add a comment, sign in
-
💡 Why this JavaScript code works even without let — but you shouldn’t do it! function greet(i) { console.log("hello " + i); } for (i = 0; i < 5; i++) { greet(i); } At first glance, it looks fine — and yes, it actually runs without any error! But here’s what’s really happening 👇 🧠 Explanation: If you don’t declare a variable using let, const, or var, JavaScript (in non-strict mode) automatically creates it as a global variable named i. That’s why your code works — but it’s not a good practice! ✅ Correct and recommended way: for (let i = 0; i < 5; i++) { greet(i); } ⚠️ Why it’s important: -Without let, i leaks into the global scope (can cause bugs later). -In 'use strict' mode, this will throw an error: i is not defined. -let keeps i limited to the loop block — safer and cleaner! 👉 In short: -It works because JavaScript is lenient. -But always use let — it’s safer, cleaner, and professional. 👩💻 Many beginners get confused when this code still works without using let! ........understand these small but important JavaScript concepts 💻✨ #JavaScript #Frontend #WebDevelopment #CodingTips #LearnToCode #Developers
To view or add a comment, sign in
-
💡 Deep Dive into JS Concepts: How JavaScript Code Executes ⚙️ Ever wondered what really happens when you hit “Run” in JavaScript? 🤔 Let’s take a simple, visual deep dive into one of the most powerful JS concepts — ✨ The Execution Context & Call Stack! 🧠 Step 1: The Global Execution Context (GEC) When your JS file starts, the engine (like Chrome’s V8) creates a Global Execution Context — the environment where everything begins 🌍 It has two phases: 🧩 Creation Phase Memory allocated for variables & functions Variables set to undefined (Hoisting!) Functions fully stored in memory ⚡ Execution Phase Code runs line by line Variables get actual values Functions are executed 🚀 🔁 Step 2: Function Execution Context (FEC) Every time a function is called, a brand-new Execution Context is created 🧩 It also runs through creation + execution phases. When the function finishes — it’s removed from memory 🧺 🧱 Step 3: The Call Stack Think of the Call Stack like a stack of plates 🍽️ Each function call adds (pushes) a new plate When done, it’s removed (popped) JS always executes the topmost plate first Example 👇 function greet() { console.log("Hello"); } function start() { greet(); console.log("Welcome"); } start(); 🪜 Execution Order: 1️⃣ GEC created 2️⃣ start() pushed 3️⃣ greet() pushed 4️⃣ greet() popped 5️⃣ start() popped 6️⃣ GEC popped ✅ ⚙️ Step 4: Quick Recap 🔹 JS runs inside Execution Contexts 🔹 Each function = its own mini world 🔹 Contexts live inside the Call Stack 🔹 Each runs through Creation → Execution “JavaScript doesn’t just run line-by-line — it builds a whole world (context) for your code to live and execute inside.” 🌐 #javascript #webdevelopment #frontend #developers #learnjavascript #executionscontext #callstack #jsengine #programming #deeplearning
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