The return Statement, Pocket Knowledge for the Era of Vibe Coding You can vibe code an entire app today. Prompt your way from idea to deployment without writing a single function from scratch. And that’s fine. But when undefined stares back at you and the AI-generated function isn’t behaving, you need to know why. Not from another prompt. From your own head. This isn’t a tutorial on return. It’s a briefing. Four things you carry with you as a developer. 1. A function is a private world When JavaScript runs a function, it creates a closed room. Variables built inside live inside. Instructions run inside. Nothing walks out on its own, no matter how clearly you can see the value sitting there. function buildLink() { const link = “https://lnkd.in/eH3akRij"; } const result = buildLink(); console.log(result); // undefined That link exists. It’s just trapped. return is the only door out of that room. No return nothing comes back. Ever. 2. return does two things at once This is the one most people miss. return doesn’t just send a value out. It stops the function dead at the same moment. Not pauses. Stops. Everything below it in that block becomes invisible to JavaScript, it won’t run, it won’t error, it will simply never execute. function buildCdnLink(packageName, version, filePath) { let link = `https://lnkd.in/eUAsawyz; if (filePath) { return; // door opens, function dies HERE link = link + “/” + filePath; // dead code. JavaScript never sees this. } return link; } return fired with nothing after it. The function answered with silence. JavaScript calls that silence undefined. Two things. Simultaneously. Send the value out, kill the function. Miss the second one and you’ll spend hours debugging code that looks completely fine. 3. Placement is everything Because return kills the function the moment it runs, where you put it is as important as what you put after it. The rule is simple, do the work first, return at the bottom. // wrong, return fires before the work is done function buildCdnLink(packageName, version, filePath) { let link = `https://lnkd.in/eUAsawyz; if (filePath) { return; // too early, work never happens link = link + “/” + filePath; } return link; } // right, work happens first, return hands it back at the end function buildCdnLink(packageName, version, filePath) { let link = `https://lnkd.in/eUAsawyz; if (filePath) { link = link + “/” + filePath; // work done first } return link; // then the door opens } Every time you write a function, ask yourself, have I done everything before I open the door? If the answer is no, return is in the wrong place. Read the full piece on Medium; [https://lnkd.in/eEu9frGx] #JavaScript #WebDevelopment #Programming #LearnToCode #SoftwareDevelopment #VibeCoding #OpenSource
Understanding Return in JavaScript
More Relevant Posts
-
6 Challenges, 1 Goal: Mastering JavaScript Logic 🚀 I’m pushing my boundaries today by knocking out 6 different coding challenges in a single session. From basic arithmetic to matrix manipulation, here’s a look at what I covered for Day 02: The Highlights: BigInt Power: Tackled "A Very Big Sum" by using BigInt to handle integers that exceed the standard 64-bit float limit. Matrix Logic: Solved "Diagonal Difference" by calculating the absolute variance between primary and secondary diagonals in a 2D array. String Formatting: Built a right-aligned "Staircase" using .repeat()—a great exercise for visualizing loops. The Code Breakdown: 1. Handling Large Sums (The BigInt Way) const arr = [1000000001, 1000000002, 1000000003, 1000000004, 1000000005] function veryBigSum(arr) { let result = 0n; for(let i = 0; i<arr.length;i++) { result += BigInt(arr[i]) } return result; } console.log(veryBigSum(arr)) } 2. 2D Array Diagonal Difference const arr = [ [1, 2, 3], [4, 5, 6], [9, 8, 9] ] function diagonalDifference(arr) { let primarySum = 0; let secondarySum = 0; let n = arr.length; for(let i =0; i<n; i++) { primarySum +=arr[i][i]; secondarySum +=arr[i][n-1-i] } return Math.abs(primarySum - secondarySum) } console.log(diagonalDifference(arr)) 3. Right-Aligned Staircase const n = 6; function staircase(n) { for(let i =1; i<=n; i++) { let spaces = ' '.repeat(n-i) let hashes = '#'.repeat(i) console.log(spaces + hashes) } } staircase(n) Building consistency is key, but today was all about momentum. Each problem solved is a tool added to the kit. 🛠️ #JavaScript #WebDevelopment #CodingChallenge #100DaysOfCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
Most developers think inheritance in JavaScript works like traditional OOP. It doesn’t. And that confusion leads to messy, over-engineered code. JavaScript uses prototypal inheritance — not classical inheritance. 👉 Objects inherit directly from other objects. 💡 There are 3 main ways inheritance works in JavaScript: 🔹 1. Prototypal Inheritance (Core Concept) const animal = { speak() { console.log("Makes a sound"); } }; const dog = Object.create(animal); dog.bark = function () { console.log("Bark"); }; dog.speak(); // inherited dog.bark(); // own method ✔ Simple ✔ Flexible ✔ Native to JS 🔹 2. Constructor Function Inheritance function Animal(name) { this.name = name; } Animal.prototype.speak = function () { console.log(this.name + " makes noise"); }; function Dog(name) { Animal.call(this, name); // inherit properties } Dog.prototype = Object.create(Animal.prototype); const d = new Dog("Tommy"); d.speak(); ✔ More structured ✔ Used in older codebases 🔹 3. Class-based Inheritance (ES6) class Animal { constructor(name) { this.name = name; } speak() { console.log(this.name + " makes noise"); } } class Dog extends Animal { bark() { console.log("Bark"); } } const dog = new Dog("Rocky"); dog.speak(); dog.bark(); ✔ Cleaner syntax ✔ Easier to read ❗ Still uses prototypes under the hood ⚡ The truth most people miss: Even with classes… 👉 JavaScript is STILL prototype-based. Classes are just syntactic sugar. 🧠 The real upgrade: Stop thinking: “Which syntax should I use?” Start thinking: “How does inheritance actually work under the hood?” Because once you understand prototypes… You don’t just write code— you understand it. What confused you more in JavaScript—closures, promises, or prototypes? 👇 #JavaScript #WebDevelopment #Programming #Frontend #Coding #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 3 of #30DaysOfJavaScript (27 April 2026) Today I learned All types of Conditionals in JavaScript আজ আমি JavaScript-এর সব ধরনের Conditionals শিখেছি 📌 Conditionals (Definition | সংজ্ঞা) 👉 Conditionals are used to control the flow of a program based on conditions. 👉 Conditionals হলো এমন logic যেটা condition অনুযায়ী program-এর flow control করে।🔹 1. if Statement (Basic Condition) 👉 Runs code only if condition is true 👉 শুধু condition true হলে কাজ করে let age = 18; if (age >= 18) { console.log("Adult"); } 🔸 2. if...else Statement 👉 One block runs if true, another if false 👉 true হলে একটা, false হলে অন্যটা let age = 16; if (age >= 18) { console.log("Adult"); } else { console.log("Not Adult"); } 🔹 3. else if Ladder (Multiple Conditions) 👉 Used when multiple conditions exist 👉 একাধিক condition check করার জন্য let marks = 75; if (marks >= 80) { console.log("A+"); } else if (marks >= 60) { console.log("A"); } else { console.log("Fail"); } 🔁 4. switch Statement (Fixed Cases) 👉 Used for multiple fixed value checks 👉 fixed value compare করার জন্য let day = "Monday"; switch (day) { case "Monday": console.log("Start Week"); break; case "Friday": console.log("Weekend Coming"); break; default: console.log("Normal Day"); } ⚡ 5. Ternary Operator (Shortcut Condition) 👉 Short form of if...else 👉 ছোটভাবে condition লেখার shortcut let age = 20; let result = (age >= 18) ? "Adult" : "Not Adult"; ⚠️ Common Mistake 👉 Forgetting break in switch 👉 Complex logic in ternary makes code unreadable 🔥 Learning 👉 Conditionals are the core of decision-making in programming 👉 Programming logic build korar base holo conditionals #JavaScript #FullStackDeveloper #LearningInPublic #WebDevelopment #30DaysChallenge
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 35 Prototypes are powerful… But let’s be honest 😅 👉 Syntax thoda confusing lagta hai 👉 Hard to read 👉 Not beginner friendly What if we could write the same thing in a **clean and simple way?** 🤔 --- ## 🔥 Solution → Classes --- ## 🔹 What are Classes? Classes are just a **clean syntax over prototypes** 👉 Same power 👉 Better readability --- ## 🔹 Without Class (Old Way) ```javascript id="clx1" function User(name) { this.name = name } User.prototype.greet = function() { console.log("Hello " + this.name) } let u1 = new User("Abhay") u1.greet() ``` --- ## 🔹 With Class (Modern Way 😎) ```javascript id="clx2" class User { constructor(name) { this.name = name } greet() { console.log("Hello " + this.name) } } let u1 = new User("Abhay") u1.greet() ``` 👉 Same result 👉 Cleaner code --- ## 🔹 Adding More Methods ```javascript id="clx3" class User { constructor(name) { this.name = name } greet() { console.log("Hello " + this.name) } sayBye() { console.log("Goodbye") } } ``` --- ## 🔥 Real Life Example Think of a **blueprint 🏗️** 👉 Class = blueprint 👉 Object = actual building Same design → multiple objects --- ## 🔥 Simple Summary Class → cleaner syntax Constructor → initialize values Methods → behavior --- ### 💡 Programming Rule **Write code that humans can read. Classes make code cleaner.** --- If you want to learn JavaScript in a **simple and practical way**, you can follow these YouTube channels: • Rohit Negi --- 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → DOM Selectors Day 22 → DOM Manipulation Day 23 → Events Day 24 → Event Bubbling Day 25 → Event Delegation Day 26 → Async JavaScript Day 27 → Promises Day 28 → Async / Await Day 29 → Fetch API Day 30 → Event Loop Day 31 → Scope Day 32 → Hoisting Day 33 → Closures Day 34 → Prototypes Day 35 → Classes Day 36 → Inheritance (Next Post) --- Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
-
I've been writing JavaScript for years, but if you'd asked me to explain closures clearly six months ago — I'd have struggled. Not because I didn't use them. I used them constantly. debounce functions, event handlers, useState under the hood — all closure-powered. I just couldn't articulate the mental model behind them. So I wrote it down. My latest article breaks down closures and currying using a framework I call the "three questions" — a way to approach any closure problem before writing a single line of code: 1. What needs to be remembered between calls? 2. What does the returned function do with that memory? 3. What does the outer function receive as setup? Once you have those three answers, the code almost writes itself. The article also covers: - Why stale closures are React's most common bug - Two flavours of closure (mutable vs immutable recursive) - How currying shows up in your daily React code without you realizing - Real implementations of debounce, memoize, and partial application If closures have always felt a bit slippery, this one's for you. https://lnkd.in/g2ZKvVUd
To view or add a comment, sign in
-
Just wrote a blog on the "new" keyword in JS Under the hood, new follows a precise process: • Creates a new empty object • Links it to the constructor’s prototype • Binds this to that object • Executes the constructor function • Returns the final instance If you're learning JavaScript or revisiting fundamentals, this will sharpen your understanding 👇 https://lnkd.in/gEitS7KJ #JavaScript #WebDevelopment #Frontend #Programming #Coding #LearnInPublic #Developers #SoftwareEngineering
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 30 JavaScript feels fast… But have you ever wondered 👇 👉 How does it handle multiple tasks at once? 👉 How does async code run without blocking? This is where the **Event Loop** comes in 😎 --- ## 🤯 The Big Confusion JavaScript is **single-threaded** 👉 It can do **one thing at a time** Then how does this work? 👇 ```javascript id="el1" console.log("Start") setTimeout(() => { console.log("Async Task") }, 0) console.log("End") ``` 👉 Output: Start End Async Task Wait… why? 🤔 --- ## 🔥 Behind the Scenes JavaScript has 3 main parts: 👉 Call Stack 👉 Web APIs 👉 Callback Queue --- ## 🔹 Step by Step Flow 1️⃣ `console.log("Start")` → runs first 2️⃣ `setTimeout` → goes to **Web API** 3️⃣ `console.log("End")` → runs next 4️⃣ Callback goes to **Queue** 5️⃣ Event Loop checks → stack empty? 6️⃣ Yes → push callback to stack 👉 Then runs → "Async Task" --- ## 🔍 Visualization ```id="viz1" Call Stack → Executes code Web APIs → Handles async tasks Queue → Stores callbacks Event Loop → Manages everything ``` --- ## 🔥 Real Life Example Think of a **restaurant 🍽️** 👉 Waiter takes order → sends to kitchen 👉 Kitchen prepares food 👉 Meanwhile waiter serves others 👉 When food is ready → serves you 👉 Event Loop = waiter managing tasks --- ## 🔥 Simple Summary JS → single-threaded Async → handled outside Event Loop → manages execution --- ### 💡 Programming Rule **JavaScript is not multi-threaded… but it behaves like it is.** --- If you want to learn JavaScript in a **simple and practical way**, you can follow these YouTube channels: • Rohit Negi • Hitesh Choudhary (Chai aur Code) --- 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → DOM Selectors Day 22 → DOM Manipulation Day 23 → Events Day 24 → Event Bubbling Day 25 → Event Delegation Day 26 → Async JavaScript Day 27 → Promises Day 28 → Async / Await Day 29 → Fetch API Day 30 → Event Loop Day 31 → Scope (Next Post) --- Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
-
We need to talk about this. In 1995, you wrote <h1>Hello World</h1>, opened it in Netscape, and people gathered around your screen like you'd just landed on the moon. In 2005, you built a dropdown menu with jQuery and your boss called you a genius. In 2015, you shipped a full React app with auth, routing, and state management — and people said "nice work." In 2026, someone types "build me a dashboard with charts, auth, and dark mode" into an AI prompt, gets it in 30 seconds, and asks you — the developer — "why does this even take you a week?" Let that satisfying sinking feeling settle in for a moment. We spent years — some of us decades — learning to code. We debugged at 3 AM. We survived the jQuery-to-Angular-to-React-to-Next pipeline. We memorized CSS specificity rules that no human should ever have to memorize. We read documentation that was written like it was actively trying to confuse us. And now, someone who's never opened a terminal can ship the same UI in minutes. Here's the thing nobody's saying out loud: That's not the problem. The problem is that we stopped appreciating the people who built the foundation that makes all of this possible. Every AI model generating code today? Trained on code that WE wrote. Every framework, every library, every Stack Overflow answer - that was us, at 2 AM, helping strangers for free. This isn't coders vs non-coders. That's a false war. The real divide is between people who understand that building software is a craft - and people who think it's just typing words into a box. To every frontend dev who hand-crafted pixel-perfect layouts before Tailwind existed. To every backend dev who wrote raw SQL before ORMs were cool. To every full-stack dev who held the entire system in their head because "we don't have budget for another engineer." You built the world these tools run on. Don't let anyone make you feel like your journey didn't matter because the destination got easier to reach. The tools changed. The craft didn't disappear. And the people who understand both - the code AND the craft - will always be irreplaceable. We, as humans, made this. All of it. Appreciate the builders. w3schools.com Stack Overflow GeeksforGeeks #html #css #javascript #frontend #backend #webdeveloper #developer
To view or add a comment, sign in
-
I’ve been writing JavaScript for around 2.6 years now, and looking back, there are a few things I really wish someone had just shown me. Not advanced stuff—just the “why didn’t I know this earlier?” kind of basics 👇 ━━━━━━━━━━━━━━━━━━━ 1️⃣ Optional Chaining (?.) I used to write checks like: if (user && user.profile && user.profile.name) Now it’s just: user?.profile?.name Feels small, but it removes so much noise from the code. ━━━━━━━━━━━━━━━━━━━ 2️⃣ Nullish Coalescing (??) I used to do: const name = user.name || "Guest" But that breaks when value is 0 or empty string. Now: const name = user.name ?? "Guest" This one saved me from so many weird bugs. ━━━━━━━━━━━━━━━━━━━ 3️⃣ Destructuring Earlier: const name = user.name const age = user.age Now: const { name, age } = user Simple change… but code becomes so much easier to scan. ━━━━━━━━━━━━━━━━━━━ 4️⃣ Promise.all() I didn’t realize how slow my code was until I learned this. Instead of waiting one by one: await fetchUsers() await fetchProducts() Now: Promise.all([...]) Everything runs together. Much faster response time. ━━━━━━━━━━━━━━━━━━━ 5️⃣ console.table() This one is underrated. Instead of messy logs everywhere, just: console.table(data) Clean rows, clean columns. Debugging becomes less painful. ━━━━━━━━━━━━━━━━━━━ Nothing fancy here. But honestly, these small things quietly level up your everyday coding. ━━━━━━━━━━━━━━━━━━━ If you’re just starting out, I’d focus on these before jumping into frameworks. They stick with you everywhere — React, Node, anything. ━━━━━━━━━━━━━━━━━━━ What about you? Which one did you start using first? 👇 #JavaScript #WebDevelopment #MERNStack #ReactJS #NodeJS #CodingLife #LearnToCode
To view or add a comment, sign in
-
Day 3/30 — JavaScript Journey JavaScript Conditionals (if / else, switch) Today your code learns to DECIDE. 🧠 Most beginners write code that runs. Great developers write code that thinks. 🔥 The Core Idea Conditionals turn JavaScript from a calculator into a decision engine. Your code stops doing everything… and starts doing the right thing at the right time. ⚡ if / else → Real-Time Decisions Use this when logic is dynamic and complex. if (user.isLoggedIn) { showDashboard(); } else { redirectToLogin(); } 👉 Reads like human thinking: “If this is true → do this, otherwise → do that.” ⚡ else if → Multiple Paths if (score > 90) { grade = "A"; } else if (score > 75) { grade = "B"; } else { grade = "C"; } 👉 Your code evaluates top → bottom First match wins. Execution stops. ⚡ switch → Clean Structured Decisions Best when comparing one value against many options switch (role) { case "admin": access = "full"; break; case "user": access = "limited"; break; default: access = "guest"; } 👉 Cleaner than multiple else if 👉 Faster to scan, easier to maintain ⚠️ Critical Concepts (Most People Miss This) • Truthiness matters if ("0") // true 😳 if (0) // false • === vs == 5 == "5" // true (loose) 5 === "5" // false (strict) 👉 Always prefer === (predictable behavior) • Missing break in switch = fall-through bug case "admin": access = "full"; // no break → next case runs too ⚠️ 🧠 Pro Insight Conditionals are not just syntax… They define your application’s behavior logic. Bad logic = bugs Good logic = clean systems 💡 When to Use What Situation Best Choice Complex logic / ranges if / else Multiple conditions else if Single variable, many values switch 🚀 Final Thought Beginners write: “Make it work” Developers evolve to: “Make it decide correctly” Because in real systems… logic is everything. If you master conditionals, you don’t just write code anymore — you control outcomes. 🔥
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