✅ Why do we use {} vs () in Arrow Functions? Most developers get confused between these two. Here’s the simple explanation 👇 1️⃣ { } → Code Block (Return Required) When you use curly braces, you’re writing normal function logic. 👉 You must write return. If you forget return, you get undefined. 2️⃣ ( ) → Implicit Return (Used for JSX) When you use parentheses, the function returns the value automatically. ✔ Cleaner ✔ Automatic return ✔ Best for multi-line JSX 🎯 Simple Rule Use { } when you have logic Use ( ) when you are directly returning something (especially JSX) #JavaScript #ReactJS #WebDevelopment #Frontend #CodingTips #JSX #ArrowFunction #LearnToCode #InterviewPrep #100DaysOfCode
Arrow Functions: { } vs () in JavaScript
More Relevant Posts
-
At first, callbacks look simple. But as async steps grow, things get messy fast. ❌ Deep nested code (code keeps going right) ❌ Hard to read and understand flow ❌ Debugging becomes painful ❌ Error handling is confusing ❌ Small changes can break big logic This situation is called Callback Hell (aka Pyramid of Doom). That’s why JavaScript evolved: ✅ Promises improved structure ✅ async/await made code readable again ✅ Logic looks almost synchronous ✅ Fewer bugs, easier debugging Once you face callback hell, you’ll never forget why modern async JS exists 🙂 #javascript #callbackhell #asyncjs #promises #asyncawait #frontend #webdev #learninginpublic #dropd #dropdai
To view or add a comment, sign in
-
-
Every extra library solves one problem and quietly introduces three more. That quick npm install feels productive ⚡ until it turns into a heavier bundle, slower pages, and another dependency you now own. Most performance issues don’t magically appear in production 🚨 they’re quietly shipped long before — right when we choose convenience over simplicity. Libraries are great. But mature engineering is knowing when not to add one. Sometimes the best optimization is writing a few lines of code yourself ✍️ #WebDevelopment #JavaScript #Frontend #Performance #CleanCode #EngineeringMindset #React #NextJS 🚀 #HappyCoding
To view or add a comment, sign in
-
-
I made a mistake today while refactoring that gave this classical error: 🔴Error: Rendered more hooks than during the previous render. Looking at the code, everything looks fine. ✅Syntax = correct ✅imports = correct 🔄 refreshed browser... multiple times But red box doesnt seem to disappear from the screen. Now i was left with no choice to leave the skimming and dig deeper. (the hard but necessary choice 😄). Finally, the StackOverflow answer saved the day. The problem was that i was calling the hooks in my page in this order: function Component() { useSomeHook(); if (loading) { return <Skeleton />; } useAnotherHook(); } I was'nt able to recall even after looking at it multiple times, that there is rule: 🔴 Do not call Hooks after a conditional return statement. 📌 What this taught me No matter how many times you read the docs, real understanding comes from making mistakes and fixing them. 🗨️If you have encountered some similar problem that you struggled solving recently, let me know in the comments. #react #javascript #nextjs
To view or add a comment, sign in
-
✨ JavaScript Spread Operator (Modern & Useful) The spread operator (...) helps you create cleaner and more readable code. Examples: const newArr = [...oldArr, 99]; const newObj = { ...oldObj, age: 25 }; Use it for: 🔹 Cloning arrays 🔹 Merging objects 🔹 Avoiding mutation Modern JavaScript is powerful when you use features like these. #javascript #webdevelopment #reactjs #nextjs #frontend #coding #js
To view or add a comment, sign in
-
💡What I Learned After Hitting These Two React Errors 1️⃣ Don’t call functions directly in JSX Writing onClick={handleClick()} executes the function during render, causing unwanted calls or even infinite loops. ✔ Use onClick={handleClick} or onClick={() => handleClick()} instead. 2️⃣ Mutating state won't trigger a re-render Updating an object like state.user.name = "John" keeps the same reference, so React won’t re-render. ✔ Always create a new object: setUser(prev => ({ ...prev, name: "John" })); Small things, big difference. 🚀 React is all about passing functions, not calling them, and immutability over mutation. #React #JavaScript #WebDevelopment #Frontend #FrontendTips
To view or add a comment, sign in
-
Differences Between Arrow Function and Normal Function. Arrow Function: Inherits this from the lexical scope. Regular Function: Has its own this. Arrow Function: Treated like a variable during context creation phase and not fully hoisted. Regular Function: Function declaration is fully hoisted. Function definition is stored in the memory during context creation phase. Arrow Function: Doesn't have the [[construct]] internal method and therefore cannot be used as constructor. Regular Function: Has [[construct]] internal method and can be used as constructor. Arrow Function: Doesn't have its own arguments object. Normal Function: Has its own argument object. #Javascript #Webdevelopment #frontend #LearningInPublic #Jscode #ES6 #Developers
To view or add a comment, sign in
-
-
Most JavaScript Developers Don’t Know This 🚨 JavaScript Truth Bomb 🚨 Most developers use var, let, and const… But don’t fully understand WHEN and WHY 👇 🔹 var ❌ Function scoped ❌ Hoisted with undefined ❌ Can cause silent bugs 🔹 let ✅ Block scoped ✅ Safer than var 🔹 const ✅ Block scoped ✅ Prevents reassignment (not mutation!) ⚠️ const does NOT make objects immutable. 📌 Real skill = knowing when NOT to use something. 👉 Which one do you use MOST in production code? 👇 Comment below (var / let / const) #JavaScript #WebDevelopment #Frontend #ProgrammingTips #Developers #CodingLife
To view or add a comment, sign in
-
-
Day 26 of #30DaysOfJavaScript on LeetCode Today’s Challenge: 2625 – Flatten Deeply Nested Array Today’s problem was all about recursion and depth control. The task was to flatten a multi-dimensional array up to a given depth n, without using the built-in Array.flat() method. Here's my solution: var flat = function (arr, n) { if (n == 0) return arr; var ans = []; for (var i = 0; i < arr.length; i++) { if (Array.isArray(arr[i])) { ans.push(...flat(arr[i], n - 1)); } else { ans.push(arr[i]); } } return ans; }; 🔗 Try the problem here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #WebDevelopment #Developers #FrontEndDevelopment #30DaysOfCode #30DaysOfJavaScript
To view or add a comment, sign in
-
-
Most developers struggle with the this keyword at the start — and it’s not their fault. The real behavior is simple: this depends entirely on how a function is called, not where it’s written. Change the caller → change the value of this. Here’s a short visual breakdown to make it click instantly. — CodebreakDev Let’s CodeBreak it down, together. #javascript #softwaredevelopment #webdevelopment #frontend #learninginpublic #codebreakdev
To view or add a comment, sign in
-
❌ Old vs ✅ New (The difference is clear) 🛑 Stop writing messy code just to access a nested property. The image below speaks for itself. Optional Chaining (?.) isn't just "syntax sugar"—it’s a necessity for: ✨ Clean Code 📖 Readability 🛡️ Crash-proof Applications Why write 5 lines when 1 line does the job better? 📉 Refactor often. Keep it clean. 🚀 👇 Tell me: Which modern JS feature saves you the most time? #JavaScript #CleanCode #WebDevelopment #ReactJS #Frontend #SajibBhattacharjee
To view or add a comment, sign in
-
More from this author
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