🚀 30 Days — 30 Coding Mistakes Beginners Make Day 4/30 I returned a value inside `forEach()`… but my array became `undefined` 😐 const doubled = numbers.forEach(n => n * 2); The mistake: `forEach()` does NOT return anything. It only runs a loop. Correct 👇 const doubled = numbers.map(n => n * 2); `map()` creates a brand new array with transformed values. Simple rule: forEach → do something map → create something This is especially important in React when rendering lists. Day 5 tomorrow 👀 #30DaysOfCode #javascript #reactjs #frontend #webdevelopment #codeinuse
30 Days of Code: Common JavaScript Mistakes
More Relevant Posts
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 7/30 I typed inside an input… clicked “Add new item”… and the text moved to another field 😳 The bug? key={index} I used array index as React key. React does not track elements. React tracks keys. When list order changes, React reuses DOM nodes, so your input becomes a different item. Fix 👇 key={item.id} Stable key = stable UI. React warnings are not decoration… they are future bugs. Day 8 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 15/30 I changed the state… but the input field didn’t update 😐 <input defaultValue={name} /> `defaultValue` only sets the initial value. After that, the DOM controls the input — not React. So even when state changed, UI didn’t. Fix 👇 <input value={name} onChange={e => setName(e.target.value)} /> Now React state controls the input. In React: Uncontrolled input → unpredictable Controlled input → reliable Day 16 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 10/30 I increased state twice… but it only updated once 😐 setCount(count + 1) setCount(count + 1) I expected +2 I got +1 Because React batches state updates. Both lines used the same OLD value of `count`. Fix 👇 setCount(prev => prev + 1) Functional updates always receive the latest state. This is very important in: counters, carts, likes, and real-time UI. Day 11 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 6/30 My React component rendered… nothing 😐 No error. No crash. Just empty UI. Code looked correct: fruits.map((fruit) => { <p>{fruit}</p> }) The mistake: I used `{}` but forgot `return`. Arrow functions with `{}` require an explicit return. React received “undefined”, so nothing was rendered. Fix 👇 fruits.map((fruit) => ( <p>{fruit}</p> )) Small brackets. Big difference. Day 7 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 9/30 I built a form in React… and used: document.getElementById("name").value It worked. But later validation broke, reset didn’t work, and UI went out of sync 😐 Because React was not controlling the input. The DOM was. Correct way 👇 Use controlled input with state. <input value={name} onChange={e => setName(e.target.value)} /> In React: State should control UI not the DOM. This is why React forms become predictable and easier to debug. Day 10 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 18/30 I clicked “Add Item”… nothing happened 😐 No error. No warning. Button worked. My code: items.push("New Task") setItems(items) The array DID change. But React didn’t update UI. Why? Because React doesn’t check contents. React checks references. Same array reference = React thinks nothing changed. Fix 👇 setItems([...items, "New Task"]) Create a NEW array instead of modifying the old one. This single mistake causes many: “React state not updating” moments. Save this — you will hit this bug in a real project. #30DaysOfCode #reactjs #javascript #frontend #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 17/30 I wrote an API call inside `useEffect`… and React showed a warning 😐 useEffect(async () => { const res = await fetch("/api/users") }, []) The mistake: `useEffect` should NOT be async. React expects the effect to return either: nothing, or a cleanup function. But async always returns a Promise. Fix 👇 Create an async function INSIDE the effect and call it. useEffect(() => { async function fetchUsers() { ... } fetchUsers() }, []) Small change. Correct lifecycle behavior. Day 18 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment
To view or add a comment, sign in
-
-
Learning React made me realize something — frontend isn’t about “changing elements.” It’s about controlling state and thinking in systems. Once that clicked, everything started making sense. Still early in the journey, but the foundation is getting stronger every day. Next stop: advanced hooks and performance optimization. Building > consuming. #ReactJS #JavaScript #FrontendDeveloper #WebDevelopment #CodingJourney #LearnInPublic #FullStackPath
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 14/30 I called an object method… and it printed: Hello undefined 😐 const user = { name: "Sam", greet: () => console.log(this.name) } The mistake: Arrow functions don’t have their own `this`. They inherit `this` from the outer scope, so it was not pointing to the object. Fix 👇 Use a normal function for object methods. Arrow functions are great for callbacks, but not for object methods. Small syntax change. Correct behavior. Day 15 tomorrow 👀 #30DaysOfCode #javascript #reactjs #frontend #webdevelopment #codeinuse
To view or add a comment, sign in
-
-
🚀 30 Days — 30 Coding Mistakes Beginners Make Day 19/30 I left a page… and React threw a scary warning 😐 “Can't perform a state update on an unmounted component” I wasn’t even touching state. The real culprit? setTimeout. The user navigated away, but the timer still executed and tried updating state. Component gone ❌ Timer still running ✔️ Fix 👇 return () => clearTimeout(timer) Always clean up inside `useEffect`. Timers, listeners, and API calls must be cancelled. Small habit. Prevents huge debugging sessions. Have you faced this warning? #30DaysOfCode #reactjs #javascript #frontend #codeinuse
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
By the way, we have easier way to achieve the same goal by using double = numbers.map(n => n*2);