While learning React, I realized that Props in React are very similar to function arguments in JavaScript. This comparison made the concept much clearer for me. In JavaScript, when we create a function, we pass data to it using arguments. Example: function greet(name) { console.log("Hello " + name) } greet("Sachin") Here, "Sachin" is an argument passed to the function, and the function uses that value. React works in a very similar way. A component is basically a function, and props are the arguments passed to that component. Example in React: function ProductCard(props) { return {props.title} } Here, title="Wireless Headphones" works just like a function argument. React collects these values into an object called props and passes it to the component. So the mental model becomes very simple: JavaScript Function → receives arguments React Component → receives props Another interesting thing is that React internally passes props as an object, which means we can access values like this: props.title props.price props.image And just like function parameters, we can also destructure props to make the code cleaner: function ProductCard({ title }) { return {title} } Understanding this connection between JavaScript arguments and React props made React feel much more intuitive to me. Sometimes the best way to understand a framework is by relating it to the fundamentals of the language it is built on. #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #CodingJourney #LearnInPublic
React Props vs JavaScript Function Arguments
More Relevant Posts
-
🚀 Still confused between JS and JSX in React? Let’s break it down. When I started learning React, I kept asking: 👉 Is JSX just JavaScript? 👉 Why does HTML appear inside JS? 👉 Which one should I use? 😬 It was confusing at first… but once I understood, everything clicked. 💡 What is JavaScript (JS)? JavaScript is the core programming language of the web. 👉 Used for logic, functions, APIs 👉 Works in all browsers 👉 No HTML inside code Example: 👉 const name = "John"; 👉 function greet() { return "Hello " + name; } 💡 What is JSX? JSX = JavaScript + HTML-like syntax (used in React) 👉 Lets you write UI inside JavaScript 👉 Makes code more readable 👉 Compiles to regular JavaScript Example: 👉 const element = <h1>Hello {name}</h1>; 💡 Key Differences: ✔ JS → Logic & functionality ✔ JSX → UI structure (what you see on screen) ✔ JS → Pure JavaScript syntax ✔ JSX → HTML-like + JavaScript combined 💡 Which one is better? 👉 They are not competitors — they work together ✔ Use JS for logic ✔ Use JSX for UI 💡 Why JSX is powerful in React: ✔ Cleaner and more readable UI code ✔ Easier to visualize components ✔ Reduces complexity compared to manual DOM manipulation 🔥 Pro tip: Don’t try to replace JavaScript with JSX — master both together. 🔥 Lesson: Great React developers don’t choose between JS and JSX — they combine them effectively. Are you comfortable with JSX or still finding it confusing? #React #JavaScript #JSX #WebDevelopment #Frontend #CodingTips #Programming
To view or add a comment, sign in
-
-
Most developers still mutate arrays in JavaScript… without realizing there’s a better way now. I used to write things like: arr.reverse() arr.sort() arr.splice() And never thought twice. Until I learned this: 👉 These methods change the original array And that’s where bugs quietly start. Now JavaScript has introduced safer alternatives 👇 And honestly… they feel like a cheat code. ⚡ toReversed() Instead of mutating: arr.reverse() ❌ Use: 👉 arr.toReversed() Original array stays untouched. ⚡ toSorted() Instead of: arr.sort() ❌ Use: 👉 arr.toSorted() No side effects. Clean logic. ⚡ toSpliced() Instead of: arr.splice() ❌ Use: 👉 arr.toSpliced() Same result. No mutation. ⚡ .with() Want to update one value in array? Before: Manual copy + update 😵 Now: 👉 arr.with(index, newValue) Simple. Predictable. ⚡ findLast() Find from the end (finally!): 👉 arr.findLast(item => condition) ⚡ findLastIndex() Same idea, but gives index: 👉 arr.findLastIndex(item => condition) 💡 The shift is clear: Old JavaScript → Mutation Modern JavaScript → Immutability And if you’re working with React, this matters even more. Because mutation = bugs + unnecessary re-renders I wish I learned this earlier. Would’ve saved a lot of debugging hours 😅 👇 Be honest: Are you still using .reverse() and .sort() directly? #javascript #frontend #reactjs #webdevelopment #coding #developers #learning #100DaysOfCode
To view or add a comment, sign in
-
React fundamentals to get right early Understanding onClick and onChange is key to handling events correctly in React A common pattern to be aware of: onClick={handleClick(id)} This executes immediately during render --- Correct approach: onClick={() => handleClick(id)} This runs only when the user clicks --- Why? React expects a function reference, not a function call - handleClick → correct - handleClick() → executes immediately --- Same concept applies to onChange: onChange={handleChange(value)} // executes immediately Better: onChange={(e) => handleChange(e.target.value)} --- Simple rule: If you need to pass arguments → use an arrow function --- Things to watch out for: - Functions running on every render - Unintended API calls - Difficult-to-debug behavior --- Benefits of correct usage: - Runs only on user interaction - More predictable component behavior - Cleaner and maintainable code --- Additional note: onClick={handleClick} (if your function expects arguments) This may result in "undefined" --- Example: {users.map(user => ( <button onClick={() => handleClick(user.id)}> Click </button> ))} --- Focusing on fundamentals like this helps build more reliable React applications #ReactJS #JavaScript #Frontend #WebDevelopment
To view or add a comment, sign in
-
-
Why do we need to call 'super(props)' in the constructor of a React component? JavaScript classes aren't magic. They are just syntactic sugar over prototypes. If you are still using (or have used) Class Components in React, you have likely typed 'super(props)' a thousand times. But do you actually know what happens if you forget it? In JavaScript, you cannot use the keyword 'this' in a constructor until you have called the parent constructor. Since your component extends 'React.Component', calling 'super()' is what actually initializes the 'this' object. If you try to access 'this.state' or 'this.props' before that call, JavaScript will throw a ReferenceError and crash your app. But why pass 'props' into it? React sets 'this.props' for you automatically after the constructor runs. However, if you want to access 'this.props' inside the constructor itself, you must pass them to 'super(props)'. If you just call 'super()', 'this.props' will be undefined until the constructor finishes execution. Most of us have moved to Functional Components where this isn't an issue. But understanding these fundamentals is what separates a developer who just writes code from one who understands the runtime. #ReactJS #Javascript #SoftwareEngineering #WebDevelopment #Coding #ProgrammingTips
To view or add a comment, sign in
-
🧠 Day 13 — Class vs Prototype in JavaScript (Simplified) JavaScript has both Classes and Prototypes — but are they different? 🤔 --- 🔍 The Truth 👉 JavaScript is prototype-based 👉 class is just syntactic sugar over prototypes --- 📌 Using Class (Modern JS) class Person { constructor(name) { this.name = name; } greet() { console.log(`Hello ${this.name}`); } } const user = new Person("John"); user.greet(); // Hello John --- 📌 Using Prototype (Core JS) function Person(name) { this.name = name; } Person.prototype.greet = function () { console.log(`Hello ${this.name}`); }; const user = new Person("John"); user.greet(); // Hello John --- 🧠 What’s happening? 👉 Both approaches: Create objects Share methods via prototype Work almost the same under the hood --- ⚖️ Key Difference ✔ Class → Cleaner, easier syntax ✔ Prototype → Core JavaScript mechanism --- 🚀 Why it matters ✔ Helps you understand how JS works internally ✔ Useful in interviews ✔ Makes debugging easier --- 💡 One-line takeaway: 👉 “Classes are just a cleaner way to work with prototypes.” --- #JavaScript #Prototypes #Classes #WebDevelopment #Frontend #100DaysOfCode
To view or add a comment, sign in
-
While writing some JavaScript logic recently, I noticed I was getting stuck on simple decision-making in code. Nothing complex just if-else and switch. But it made me realize I was writing conditions without really thinking through the flow properly. So I went back, broke it down, and tried to understand how control flow actually works. That led me to write this blog. If you’re learning JavaScript or revisiting the basics, this might help: https://lnkd.in/dNjZqNuS #JavaScript #LearningInPublic #WebDevelopment #BuildInPublic #chaicode #chaiaurcode
To view or add a comment, sign in
-
Day 1 of learning React Today marks the beginning of my journey into React, and I’m excited to share what I’ve learned so far. I started by understanding how to set up React using external libraries and how Babel plays an important role. Since browsers don’t understand JSX directly, Babel compiles it into regular JavaScript that the browser can execute. One thing I’ve realized already is that React makes building user interfaces more structured and scalable. Instead of writing plain JavaScript, we use JSX a syntax that looks like HTML but works inside JavaScript. Here are a few core concepts I explored today: • Components Components are like reusable building blocks for your UI. Instead of writing one large file, you break your interface into smaller, manageable pieces. Example: function Welcome() { return Hello, World!; } • Fragments Sometimes you want to return multiple elements without adding unnecessary divs to your HTML. That’s where fragments come in. Example: <> • Props Props (short for properties) allow you to pass data from one component to another, making your components dynamic. Example: function Welcome(props) { return Hello, {props.name}; } • Conditional Rendering (Guard Operator) In React, we can use the “&&” operator directly inside JSX to render something based on a condition. Example: {isLoggedIn && Welcome back!} This will only display the message if isLoggedIn is true. It hasn’t been easy stepping into something new, but I’m committed to learning and improving every day. #React #JavaScript #FrontendDevelopment #WebDevelopment #LearningInPublic #CodingJourney #100DaysOfCode #BuildInPublic
To view or add a comment, sign in
-
-
💡 𝗘𝘃𝗲𝗿 𝗪𝗼𝗻𝗱𝗲𝗿𝗲𝗱 𝗪𝗵𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗨𝘀𝗲𝘀 𝗖𝗮𝗹𝗹𝗯𝗮𝗰𝗸𝘀? ⤵️ Callbacks in JavaScript: Why They Exist 🧠 🔗 𝗥𝗲𝗮𝗱 𝗵𝗲𝗿𝗲: https://lnkd.in/ey9JfCas 𝗧𝗼𝗽𝗶𝗰𝘀 𝗰𝗼𝘃𝗲𝗿𝗲𝗱 ✍🏻: ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ ⇢ Why JavaScript can't "wait" like other languages ⇢ What callbacks actually are (simple mental model) ⇢ Functions as values — the core JS superpower ⇢ Sync vs Async callbacks explained clearly ⇢ Real-world examples: events, setTimeout, array methods, Node.js ⇢ The async problem: why return values don’t work ⇢ Callback Hell (Pyramid of Doom) — why it happens ⇢ Tradeoffs of callbacks in real applications ⇢ Where callbacks are still used today (React, Node, browser APIs) ⇢ How this leads to Promises & async/await Thanks Hitesh Choudhary Sir & Piyush Garg Sir, and the amazing Chai Aur Code community 🙌 #ChaiAurCode #JavaScript #AsyncProgramming #WebDevelopment #SystemDesign #Programming #Hashnode
To view or add a comment, sign in
-
"I started learning React JS." "You finished JavaScript right?" "..." "You finished JavaScript right?" This meme hurts because it is true. Every week someone asks me why React feels so confusing. Why state management makes no sense. Why useEffect keeps behaving unexpectedly. Why everything feels like magic they cannot control. Almost always the answer is the same. They skipped JavaScript fundamentals and jumped straight to React. React is not a replacement for JavaScript. It is JavaScript. Every pattern in React — components, props, state, hooks, context — is built on JavaScript concepts that feel obvious when you know the language and mysterious when you do not. If you are struggling with React right now, here is the honest advice: Stop. Go back to JavaScript. Spend two to four weeks on the fundamentals. Closures, promises, async/await, array methods, destructuring, and how the event loop works. Then come back to React. It will feel completely different. The time you spend on JavaScript fundamentals is not a detour. It is the fastest path to actually understanding React. Did you learn JavaScript properly before React or did you skip ahead and regret it? #JavaScript #React #WebDevelopment #Developers #ProgrammerHumor #LearningToCode #Frontend
To view or add a comment, sign in
-
-
💡 Understanding Scope in JavaScript One of the most important concepts in JavaScript is Scope. Scope defines where variables can be accessed in your code. There are three main types of scope in JavaScript: 🔹 Global Scope Variables declared outside any function are accessible anywhere in the program. let name = "Muneeb"; function showName() { console.log(name); } showName(); // Accessible because it's global 🔹 Function Scope Variables declared inside a function can only be used inside that function. function greet() { let message = "Hello"; console.log(message); } greet(); // console.log(message); ❌ Error 🔹 Block Scope Variables declared with "let" and "const" inside "{ }" are only accessible within that block. if (true) { let age = 25; console.log(age); } // console.log(age); ❌ Error 📌 Understanding scope helps developers write cleaner code and avoid bugs related to variable access. Mastering these fundamentals makes JavaScript much easier to understand and improves problem-solving skills. #JavaScript #WebDevelopment #FrontendDeveloper #Coding #LearnToCode
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