One Frontend Interview Question That Never Goes Away: async vs defer This is one of the most commonly asked frontend interview questions — and many candidates answer it without understanding why it exists. Before talking about async and defer, you must understand how the browser parses HTML. 🧠 How HTML Parsing Actually Works When the browser loads a page, it parses HTML from top to bottom. If it encounters a <script> tag without async or defer: 1. HTML parsing stops 2. The JavaScript file is downloaded 3. The script is executed 4. HTML parsing resumes ⚠️ This is blocking behavior, and it can significantly slow down page load and delay rendering. 🚀 What async Does With async: Script downloads in parallel while HTML continues parsing Script executes as soon as it finishes downloading HTML parsing pauses only during execution Execution order is NOT guaranteed ✅ Best suited for: Scripts that are independent Scripts that don’t rely on DOM or other scripts 📌 Common examples: Analytics Ads Tracking scripts 🕒 What defer Does With defer: Script downloads in parallel with HTML parsing Execution is delayed until HTML parsing completes Scripts execute in the same order they appear in the document ✅ Best suited for: Scripts that depend on the DOM Scripts that rely on other scripts 🧠 Easy Rule to Remember Independent + performance-focused → async DOM-dependent + ordered execution → defer Understanding this small detail shows interviewers that you know how browsers work — not just JavaScript syntax. And yes, it directly impacts page performance and frontend architecture. 👉 Follow Rahul R Jain for more real interview insights, React fundamentals, and practical frontend engineering content. #JavaScript #FrontendDevelopment #WebPerformance #BrowserInternals #WebDev #FrontendInterview #LearningInPublic
async vs defer: Understanding Browser Parsing
More Relevant Posts
-
⚛️ Top 150 React Interview Questions – 28/150 📌 Topic: The useRef Hook 🔹 WHAT is useRef? useRef is a React Hook that returns a mutable ref object. Think of it as a box that can hold any value (like a DOM element or a variable) that stays the same between re-renders. ⚠️ Most important rule: Changing a ref does NOT cause the component to re-render. 🔹 WHY do we need useRef? 1️⃣ Accessing the DOM Sometimes you need to: Focus an input field Measure the size of a div React handles most DOM work automatically, but useRef gives you a direct grab handle when needed. 2️⃣ Storing values without re-rendering useState → value change = UI re-render useRef → value change = NO UI re-render So if you want to track something (like click count) without refreshing the screen, useRef is the right tool. 🔹 HOW do you use useRef? Syntax: const myRef = useRef(initialValue); It returns an object with one property: myRef.current Example: Focusing an Input function TextInputWithFocusButton() { const inputEl = useRef(null); // 1. Create the ref const onButtonClick = () => { inputEl.current.focus(); // 3. Use 'current' }; return ( <> <input ref={inputEl} type="text" /> {/* 2. Attach the ref */} <button onClick={onButtonClick}>Focus the input</button> </> ); } 🔹 WHERE is useRef used? Managing Focus → Search bar auto-focus Media Playback → Control <video> / <audio> Third-Party Libraries → D3.js, Google Maps (need direct DOM access) Storing Previous Values → Track earlier state values 📝 Summary for your notes: useRef is like a Laser Pointer 🔦 — it lets you point directly at something on the screen (DOM). It’s also like a Secret Notebook 📒 where you store data without forcing the UI to update. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
𝗜𝗳 𝘆𝗼𝘂 𝗵𝗮𝘃𝗲 𝘆𝗼𝘂𝗿 𝗳𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗶𝗻 𝗷𝘂𝘀𝘁 𝟮 𝗱𝗮𝘆𝘀, 𝗱𝗼𝗻'𝘁 𝗽𝗮𝗻𝗶𝗰 𝗮𝗻𝗱 𝗱𝗼𝗻'𝘁 𝘁𝗿𝘆 𝘁𝗼 𝗰𝗼𝘃𝗲𝗿 𝗲𝘃𝗲𝗿𝘆𝘁𝗵𝗶𝗻𝗴, 𝗷𝘂𝘀𝘁 𝘀𝘁𝘂𝗱𝘆 𝘁𝗵𝗲𝘀𝗲 𝘁𝗼𝗽𝗶𝗰𝘀. If your interview is close, this is the highest-ROI prep list: 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗳𝘂𝗻𝗱𝗮𝗺𝗲𝗻𝘁𝗮𝗹𝘀 (𝗻𝗼𝗻-𝗻𝗲𝗴𝗼𝘁𝗶𝗮𝗯𝗹𝗲) • var, let, const + block/function scope • Hoisting & Temporal Dead Zone • Closures & lexical environment • this binding, call / apply / bind, arrow functions • Prototype chain & inheritance • ES6 classes vs prototypes (what is syntax sugar, what is not) 👉 These explain why most bugs happen. 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻 & 𝗮𝘀𝘆𝗻𝗰 𝗯𝗲𝗵𝗮𝘃𝗶𝗼𝗿 • Event loop: call stack, task queue, microtask queue • Promises & chaining • async / await patterns (error handling, sequencing) • Stale closures in async code 👉 Almost every “why does this behave weirdly?” question lives here. 𝗗𝗮𝘁𝗮 & 𝗿𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲𝘀 • Equality & coercion (== vs ===, truthy/falsy) • Deep vs shallow copy • Object & array references • map, filter, reduce, find, some, every 👉 Interviewers love probing reference bugs. 𝗕𝗿𝗼𝘄𝘀𝗲𝗿 & 𝗗𝗢𝗠 (𝗼𝗳𝘁𝗲𝗻 𝘂𝗻𝗱𝗲𝗿𝗲𝘀𝘁𝗶𝗺𝗮𝘁𝗲𝗱) • DOM events & event delegation • Reflow vs repaint (what actually triggers them) • Debouncing vs throttling • requestAnimationFrame (when and why) 👉 This separates frontend engineers from React users. 𝗡𝗲𝘁𝘄𝗼𝗿𝗸 & 𝘀𝗶𝗱𝗲 𝗲𝗳𝗳𝗲𝗰𝘁𝘀 • Fetch API • AbortController (why cancellation matters) • CORS basics (what FE controls vs what it doesn’t) • Web storage vs cookies (when to use what) 👉 Real-world frontend is async + network heavy. 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 & 𝗮𝗿𝗰𝗵𝗶𝘁𝗲𝗰𝘁𝘂𝗿𝗲 𝘀𝗶𝗴𝗻𝗮𝗹𝘀 • Pure functions & testable code • When memoization helps vs hurts • Web Workers (what problems they actually solve) 👉 You don’t need mastery you need reasoning. 𝗛𝗼𝘄 𝘁𝗼 𝘀𝘁𝘂𝗱𝘆 𝘁𝗵𝗲𝘀𝗲 𝗶𝗻 𝟮 𝗱𝗮𝘆𝘀 Don’t memorize definitions. For each topic, practice answering: Why does this exist? What breaks if I misuse it? Where have I seen this bug in real code? That’s how interviews probe. My eBook will save you weeks of scattered prep. 📘 300+ JS and ReactJS questions 📘 60 System Design Question (HLD and LLD) 👉✅️Grab ebook here: https://lnkd.in/g9hdUJkf #frontend #javascript #reactjs #interviewpreparation #frontenddeveloper #webdevelopment #career
To view or add a comment, sign in
-
⚛️ Top 150 React Interview Questions — 49/150 📌 Topic: onChange vs. onClick 🔹 WHAT is it? These are Event Handlers in React — they tell React when to respond to user actions. onChange → Triggers whenever the value of an input changes (typing, selecting). onClick → Triggers when a user clicks or taps a button or link. 🔹 WHY are they designed this way? React needs to clearly separate data input from user actions. Real-time Tracking (onChange): Keeps React state perfectly in sync with user input (live search, character count, password strength). Action Triggering (onClick): Used for final actions like submit, delete, open modal, or send request. Fewer Bugs & Better UX: Using the right event avoids accidental actions and improves accessibility (keyboard users). 🔹 HOW do you use them? (Implementation) function SimpleSearch() { const [text, setText] = useState(""); const trackTyping = (e) => { setText(e.target.value); // onChange }; const startSearch = () => { alert("Searching for: " + text); // onClick }; return ( <> <input onChange={trackTyping} /> <button onClick={startSearch}>Go</button> </> ); } 🔹 WHERE are best practices? ✅ Use onChange for <input>, <textarea>, <select> ✅ Use onClick for buttons & actions ❌ Avoid onClick on <div> or <span> unless necessary (use <button> for accessibility) 📝 Short Summary (for notes): onChange = Mirror 🪞 Shows exactly what’s happening inside the input — live. onClick = Doorbell 🔔 Nothing happens until you press it. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 48/150 📌 Topic: Refs in Forms 🔹 WHAT is it? A Ref (Reference) lets you access a DOM element directly in React. In forms, instead of tracking input values with state, you use a ref to read or control the input only when needed. 👉 React State = Declarative 👉 Refs = Imperative (direct DOM access) 🔹 WHY is it designed this way? React prefers state, but sometimes direct DOM access is required. ✅ Focus Management Auto-focus an input using .focus() (login, search, OTP forms) ✅ Performance Optimization Reading values via refs does not cause re-renders — great for large forms ✅ Native DOM Control Play/pause media, trigger animations, or read values instantly 🔹 HOW do you do it? (The Implementation) Use the useRef hook in Functional Components 👇 import { useRef } from "react"; function LoginForm() { const emailRef = useRef(null); const handleLogin = () => { const email = emailRef.current.value; console.log("Email:", email); if (!email) { emailRef.current.focus(); } }; return ( <> <input ref={emailRef} placeholder="Enter email" /> <button onClick={handleLogin}>Login</button> </> ); } 🔹 WHERE are the best practices? ✔ Use refs for focus, text selection, animations, and uncontrolled forms ✔ File inputs are always uncontrolled → refs required ❌ Don’t replace state with refs everywhere ❌ Never use document.getElementById() in React — use useRef 📝 Summary for your notes A Ref is like a Laser Pointer 🔦 Instead of announcing to the whole room (state change), you point directly to the exact element (DOM) and control it. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 37/150 📌 Topic: Importance of ‘Keys’ in Lists 🔹 WHAT is it? A Key is a special string attribute that you must include when rendering lists in React. Keys help React identify which items in an array have changed, been added, or been removed, giving each element a stable identity. 🔹 WHY is it designed this way? React uses a process called Reconciliation (Diffing) to update the UI efficiently. Performance: Instead of re-rendering every item, React uses keys to match existing elements and only move the DOM nodes that actually changed. State Preservation: Keys ensure that internal state (like text inside an input field) stays with the correct item even when the list is sorted or shuffled. Accuracy: They prevent “ghosting” bugs where data from a deleted row appears in a different row. 🔹 HOW do you do it? (The Implementation) Keys must be added to the outermost element inside the .map(). Correct Way (Using Unique IDs): function UserList({ users }) { return ( <ul> {users.map((user) => ( <li key={user.id}>{user.name}</li> ))} </ul> ); } 🔹 WHERE are the best practices? When to Use: Always use keys whenever you render a list from an array. Use Stable IDs: Prefer unique IDs from your data (like database IDs) instead of array indexes, especially if the list can be reordered. Avoid Random Keys: Never use Math.random() as a key. It forces components to remount on every render, causing performance issues and state loss. 📝 Summary for your notes: Keys are like Roll Numbers in a classroom 🎓 Even if students change seats, the teacher (React) can still identify everyone correctly using their roll number. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 26/150 📌 Topic: The useEffect Hook & Dependency Array 🔹 WHAT is useEffect? useEffect is a React Hook used to perform side effects in a component. A side effect is anything that affects something outside the component’s render, such as: Fetching data from an API Setting up a timer Subscriptions Manual DOM changes 🔹 WHY do we need useEffect? A React component’s main job is to calculate and return UI. If you place side-effect code (like an API call) directly inside the component body: It runs on every re-render Can cause performance issues Can lead to infinite loops useEffect gives you control over when that code should run. 🔹 HOW do you use useEffect? Syntax: useEffect(() => { // side effect code }, [dependencyArray]); The first argument is the effect logic The second argument decides when the effect runs 🔹 WHERE does the Dependency Array matter? The Dependency Array is the trigger list. No array useEffect(() => {}) Runs after every render (usually a mistake) Empty array useEffect(() => {}, []) Runs only once (after first render) → API calls, timers With dependencies useEffect(() => {}, [count]) Runs on mount and whenever count changes Cleanup happens by returning a function inside useEffect (e.g. clearing timers, unsubscribing). 📝 Summary for your notes: useEffect is like a Post-it note for React: “After you finish rendering the UI, go do this task.” The Dependency Array decides whether that task should run again or not. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 22/150 📌 Topic: How to Update State in React? This is a core React skill — and a common source of bugs if done incorrectly. 🔑 What is the correct method? In Functional Components, React gives you an updater function from the useState hook. You must never modify state directly. ❌ Incorrect: count = count + 1; (React won’t know the value changed, so the UI won’t update) ✅ Correct: setCount(count + 1); (This tells React to re-render the component) ⚡ Why use the updater function? React performs batching — it may group multiple state updates together for performance. Using the setter function ensures React’s reconciliation process runs correctly and the UI stays in sync. 🛠️ How to update different types of state? A. Simple values (numbers / strings): setCount(5); setName("Amit"); B. Based on previous state (Best Practice): If the new state depends on the old state, always use a callback: setCount(prevCount => prevCount + 1); This avoids bugs caused by React’s asynchronous updates. C. Objects & Arrays (Immutability): // Object setUser({ ...user, age: 25 }); // Array setItems([...items, newItem]); 🚫 Where people go wrong Updating state inside render: Calling setState directly in the component body causes an infinite render loop. Expecting immediate updates: Logging state right after setState still shows the old value because updates are scheduled, not instant. 📝 Final takeaway: Updating state is like publishing a new edition of a book 📘 You don’t edit the old copy (mutation). You publish a new version and give it to the reader (React). 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
𝗜𝗳 𝘆𝗼𝘂 𝘄𝗮𝗻𝘁 𝗯𝗲𝘁𝘁𝗲𝗿 𝗳𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗿𝗲𝘀𝘂𝗹𝘁𝘀, 𝗽𝗿𝗲𝗽𝗮𝗿𝗲 𝗮𝗻𝘀𝘄𝗲𝗿𝘀 𝗶𝗻 𝘁𝗵𝗶𝘀 𝗳𝗼𝗿𝗺𝗮𝘁. Most candidates prepare topics. Strong candidates prepare answer structures. Here’s a simple framework you can apply to almost any JavaScript / React interview question and it works because it mirrors how interviewers think. The 4-step answer structure interviewers respond to When you’re asked any technical question, consciously follow this order: 1️⃣ 𝗦𝘁𝗮𝘁𝗲 𝘁𝗵𝗲 𝗰𝗼𝗿𝗲 𝗶𝗱𝗲𝗮 (𝟭𝟬–𝟭𝟱 𝘀𝗲𝗰𝗼𝗻𝗱𝘀) Show that you understand the concept before diving into details. Example: “Closures allow a function to retain access to its lexical scope even after the outer function has executed.” This sets confidence early. 2️⃣ 𝗘𝘅𝗽𝗹𝗮𝗶𝗻 𝘄𝗵𝘆 𝗶𝘁 𝗲𝘅𝗶𝘀𝘁𝘀 Most candidates skip this. Interviewers notice. Example: “This exists because JavaScript relies heavily on functions as first-class citizens, and without closures, async code and callbacks would be impossible to reason about.” Now you’re no longer just recalling you’re reasoning. 3️⃣ 𝗚𝗶𝘃𝗲 𝗼𝗻𝗲 𝗿𝗲𝗮𝗹-𝘄𝗼𝗿𝗹𝗱 𝘂𝘀𝗲 𝗰𝗮𝘀𝗲 Not a textbook example. A real one. Example: “This is commonly used in debounced inputs, event handlers, or when preserving state inside async flows.” This bridges theory to production. 4️⃣ 𝗔𝗰𝗸𝗻𝗼𝘄𝗹𝗲𝗱𝗴𝗲 𝗼𝗻𝗲 𝗽𝗶𝘁𝗳𝗮𝗹𝗹 This is where differentiation happens. Example: “Closures can also cause memory leaks if references are unintentionally retained, especially with long-lived listeners.” Now your answer survives follow-ups. Why this works Interviewers are subconsciously checking: clarity of thought, depth, not verbosity, awareness of trade-offs.This structure hits all three. How to practice this (important) Take any interview question you know and rehearse it using only these 4 steps. If you can’t complete one step cleanly that’s your gap. No new topics needed. Just better structure This is exactly how I’ve structured the questions in Frontend Interview Blueprint: Grab eBook here: 👉 https://lnkd.in/g9hdUJkf ✅️ 300+ JavaScript & React interview questions (70% coding) ✅️ Each question pushes you to explain concept → reason → usage → pitfall ✅️ 60 system design questions (HLD + LLD) #FrontendInterview #WebDevelopment #JavaScript #ReactJS #CodingTips #FrontendEngineer #TechCareers
To view or add a comment, sign in
-
I once walked out of a #React interview thinking: “I know React… why did this feel so hard?” The questions weren’t tricky. They were fundamental. ❌ “Explain Virtual DOM” ❌ “Props vs State” ❌ “Why keys matter?” ❌ “useEffect dependencies?” That’s when I realized something important 👇 Most React interviews don’t test how much you’ve built — They test how clearly you understand what you already use every day. Curated with: ✅ Basic → Intermediate → Advanced questions ✅ Clear, interview-friendly explanations ✅ Real concepts interviewers care about Perfect if you’re: 🎯 Preparing for frontend/full-stack interviews 🎯 Switching companies 🎯 Revising React after long project work Because in interviews, confidence comes from clarity, not cramming. 📎 ReactJS Interview Questions PDF attached 👉 Follow Ankit Sharma Sharma for interview prep, system design, and practical engineering insights. #ReactJS #FrontendInterviews #JavaScript #WebDevelopment #SDE #InterviewPreparation
To view or add a comment, sign in
-
⚛️ Top 150 React Interview Questions – 50/150 📌 Topic: Handling Multiple Inputs 🔹 WHAT is it? Handling multiple inputs is a technique where you use one state object and one change handler to manage many form fields at once, instead of creating separate state variables for each input. This approach keeps all form data in a single place. 🔹 WHY use it? When a form has many fields (Name, Email, Phone, etc.), multiple useState hooks quickly become messy. ✅ Cleaner Code Write the logic once — it works for any number of inputs. ✅ Easy API Submission All form data is already inside one object, ready to send. ✅ Scalable Adding a new input only requires adding one key to the state object. 🔹 HOW do you implement it? Each input gets a name attribute that matches the key in state. We update the state dynamically using computed property names. const [form, setForm] = useState({ firstName: "", email: "" }); const handleChange = (e) => { const { name, value } = e.target; setForm({ ...form, [name]: value }); }; // JSX <input name="firstName" onChange={handleChange} /> <input name="email" onChange={handleChange} /> 👉 Only the field you type in gets updated. 🔹 WHERE / Best Practices ✔ Always use the spread operator (...form) → Forgetting it will overwrite other fields ✔ Ensure name attributes exactly match state keys ✔ Best suited for forms with more than 2 inputs 📝 Summary (Easy to Remember) Handling multiple inputs is like using a multi-tool 🛠️ Instead of carrying a different tool for every task (multiple states), you use one smart tool with dynamic parts (object keys). 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #ReactInterview #FrontendDevelopment #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions #FrontendEngineer
To view or add a comment, sign in
-
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