🚀 Day 2/30 – Frontend Interview Questions Series Let’s level up your JS fundamentals today 💡 ❓ Q1: What is the difference between "==" and "===" in JavaScript? 👉 "==" (Loose Equality) - Compares values after type conversion - Example: 5 == "5" // true 👉 "===" (Strict Equality) - Compares value + type (no conversion) - Example: 5 === "5" // false ✅ Best Practice: Always use "===" to avoid unexpected bugs. --- ❓ Q2: What is Hoisting in JavaScript? 👉 Hoisting is JavaScript's behavior of moving declarations to the top of their scope. Example: console.log(a); // undefined var a = 10; 🔍 Behind the scenes: var a; console.log(a); a = 10; ⚠️ Note: - "var" is hoisted with "undefined" - "let" and "const" are hoisted but stay in Temporal Dead Zone (TDZ) --- ❓ Q3: What is Closure? 👉 A closure is a function that remembers variables from its outer scope, even after the outer function has finished executing. Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 💡 Closures are widely used in: - Data hiding - Callbacks - React hooks #JavaScript #FrontendDeveloper #InterviewPreparation #ReactJS #WebDevelopment #CodingInterview
JavaScript Fundamentals: Loose vs Strict Equality, Hoisting, and Closures
More Relevant Posts
-
Great insight Rushikesh Chavhan You can also add more example like what happen when you use arrow function and normal function. also when same function name and variable decaled with var then how hositing happrns.
Front-End Developer @ Laminaar Aviation Infotech | 3 Years Experience | HTML | CSS | JavaScript | React.js | Nodejs | Web Developer | PG-DAC.
🚀 Day 2/30 – Frontend Interview Questions Series Let’s level up your JS fundamentals today 💡 ❓ Q1: What is the difference between "==" and "===" in JavaScript? 👉 "==" (Loose Equality) - Compares values after type conversion - Example: 5 == "5" // true 👉 "===" (Strict Equality) - Compares value + type (no conversion) - Example: 5 === "5" // false ✅ Best Practice: Always use "===" to avoid unexpected bugs. --- ❓ Q2: What is Hoisting in JavaScript? 👉 Hoisting is JavaScript's behavior of moving declarations to the top of their scope. Example: console.log(a); // undefined var a = 10; 🔍 Behind the scenes: var a; console.log(a); a = 10; ⚠️ Note: - "var" is hoisted with "undefined" - "let" and "const" are hoisted but stay in Temporal Dead Zone (TDZ) --- ❓ Q3: What is Closure? 👉 A closure is a function that remembers variables from its outer scope, even after the outer function has finished executing. Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 💡 Closures are widely used in: - Data hiding - Callbacks - React hooks #JavaScript #FrontendDeveloper #InterviewPreparation #ReactJS #WebDevelopment #CodingInterview
To view or add a comment, sign in
-
🚀 JavaScript Interview Questions Every Developer Should Know Here are some useful JS questions with simple answers 👇 🔹 1. What is the output? console.log(typeof null); 👉 Answer: "object" 💡 This is a well-known JavaScript bug. 🔹 2. What is closure? 👉 A closure is a function that remembers variables from its outer scope even after the outer function has finished execution. function outer() { let count = 0; return function inner() { count++; return count; }; } 🔹 3. Difference between == and ===? 👉 == → compares value (loose equality) 👉 === → compares value + type (strict equality) 🔹 4. What is hoisting? 👉 JavaScript moves variable and function declarations to the top of their scope before execution. 🔹 5. What will be the output? let a = 10; (function() { console.log(a); let a = 20; })(); 👉 Answer: ❌ ReferenceError 💡 Due to Temporal Dead Zone (TDZ) 🔹 6. What is event loop? 👉 It handles async operations by managing the call stack and callback queue. 🔹 7. What is this keyword? 👉 Refers to the object that is calling the function (depends on context). 🔹 8. What is a promise? 👉 A promise represents a value that may be available now, later, or never. 🔹 9. What is async/await? 👉 Syntactic sugar over promises to write async code like synchronous code. 🔹 10. What is debounce? 👉 Limits how often a function runs. Useful for search inputs. 🔥 Save this for your next interview 💬 Comment your favorite question 🔁 Share with your developer friends #JavaScript #WebDevelopment #Frontend #InterviewPrep #Coding
To view or add a comment, sign in
-
🚀 Day 4/30 – Frontend Interview Series 🔥 Topic: Closures in JavaScript 💡 What is a Closure? A closure is created when a function “remembers” its outer variables even after the outer function has finished executing. 👉 In simple words: A function + its lexical scope = Closure 🧠 Example: function outerFunction() { let count = 0; return function innerFunction() { count++; console.log(count); }; } const counter = outerFunction(); counter(); // 1 counter(); // 2 counter(); // 3 🔍 Why Closures are Important? ✔ Data hiding / Encapsulation ✔ Used in callbacks ✔ Used in React (hooks internally use closures) ✔ Helps in maintaining state ⚡ Real-world Use Case: function createUser(name) { return function() { console.log(`User: ${name}`); }; } const user1 = createUser("Rushikesh"); user1(); // User: Rushikesh 🎯 Interview Questions: ❓ What is closure in JavaScript? ❓ Where are closures used in real applications? ❓ How closures help in data privacy? #Day4 #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #CodingInterview #LearnInPublic #Developers
To view or add a comment, sign in
-
🚀 Day 8/30 – Frontend Interview Series 📌 What is Async/Await? async/await is a modern way to handle asynchronous operations in JavaScript. It makes your code look cleaner and easier to read compared to Promises and callbacks. 🔹 1. async Keyword Used before a function Always returns a Promise async function greet() { return "Hello"; } greet().then(console.log); // Hello 🔹 2. await Keyword Used inside async functions only Waits for a Promise to resolve async function fetchData() { let data = await Promise.resolve("Data received"); console.log(data); } fetchData(); 🔥 3. Example (Real-world API) async function getUser() { try { let response = await fetch("https://lnkd.in/dEvCbUij"); let data = await response.json(); console.log(data); } catch (error) { console.log("Error:", error); } } ⚡ Why use async/await? ✔ Cleaner code (no .then() chaining) ✔ Easier error handling (try...catch) ✔ Looks like synchronous code ✔ Better readability in large apps #JavaScript #WebDevelopment #Frontend #ReactJS #CodingJourney
To view or add a comment, sign in
-
Most developers think they understand async JavaScript… until interviews expose the gaps. Here’s the truth 👇 JavaScript is single-threaded, but it handles async work using: - Call Stack - Web APIs - Callback Queue - Event Loop The biggest mistake I made earlier: I used async/await without truly understanding what happens behind the scenes. Example: setTimeout(() => console.log("A"), 0); Promise.resolve().then(() => console.log("B")); console.log("C"); Output? 👉 C → B → A Why? Because: - Synchronous code runs first - Microtasks (Promises) run next - Macrotasks (setTimeout) run last This understanding alone can: ✔ Help you debug complex issues ✔ Improve performance decisions ✔ Crack frontend interviews Currently diving deeper into: - Promises & chaining - Currying & composition - Advanced JS patterns If you're preparing for frontend interviews, this is a must-master area. #javascript #frontend #webdevelopment #softwareengineering #remotework
To view or add a comment, sign in
-
Most developers think they understand async JavaScript… until interviews expose the gaps. Here’s the truth 👇 JavaScript is single-threaded, but it handles async work using: - Call Stack - Web APIs - Callback Queue - Event Loop The biggest mistake I made earlier: I used async/await without truly understanding what happens behind the scenes. Example: setTimeout(() => console.log("A"), 0); Promise.resolve().then(() => console.log("B")); console.log("C"); Output? 👉 C → B → A Why? Because: - Synchronous code runs first - Microtasks (Promises) run next - Macrotasks (setTimeout) run last This understanding alone can: ✔ Help you debug complex issues ✔ Improve performance decisions ✔ Crack frontend interviews Currently diving deeper into: - Promises & chaining - Currying & composition - Advanced JS patterns If you're preparing for frontend interviews, this is a must-master area. #javascript #frontend #webdevelopment #softwareengineering #remotework
To view or add a comment, sign in
-
🔥 Top JavaScript Tricky Interview Questions 🔥 These are usefull for you guys 1️⃣ Why does [] == ![] return true? Because ![] becomes false, then both sides are type-converted. 👉 JS coercion magic. 2️⃣ What will typeof null return? It returns object. 👉 This is a well-known JavaScript bug. 3️⃣ Output of: console.log(1 + "2" + 3) Result: "123" 👉 String concatenation happens left to right. 4️⃣ Output of: console.log(0.1 + 0.2 === 0.3) Result: false 👉 Floating-point precision issue. 5️⃣ Why does NaN !== NaN? Because NaN is not equal to anything — even itself. 👉 Use isNaN() to check. 6️⃣ What is the output of: console.log(typeof NaN)? Result: "number" 👉 Another classic trap. 7️⃣ Difference between null and undefined undefined → variable declared but not assigned null → explicitly assigned empty value 👉 Intent matters. 8️⃣ What happens if you forget await in async function? Function continues execution without waiting. 👉 Can cause silent bugs. 9️⃣ Output of: console.log([] + []) Result: "" (empty string) 👉 Arrays are converted to strings. 🔟 Why is setTimeout(fn, 0) not executed immediately? Because it goes through the Event Loop. 👉 Call stack must be empty first. 💡 Tricky JS questions test understanding of how JavaScript really works. #Trick #js #javascript #Interview #follow #@all #Tips
To view or add a comment, sign in
-
𝐖𝐡𝐲 𝐃𝐨 𝐖𝐞 𝐔𝐬𝐞 𝐂𝐥𝐨𝐬𝐮𝐫𝐞𝐬 𝐢𝐧 𝐑𝐞𝐚𝐜𝐭 𝐉𝐒? 🤔 Closures are one of the most important concepts in JavaScript… and React uses them everywhere. But many developers don’t realize it 👇 What is a closure? A closure is when a function remembers the variables from its outer scope even after that scope has finished execution. How React uses closures 👇 🔹 Event Handlers Functions like onClick capture state values at the time they are created 🔹 Hooks (useState, useEffect) Hooks rely on closures to access state and props inside functions 🔹 Async operations (setTimeout, API calls) Closures hold the state values when the async function was created Example 👇 const [count, setCount] = useState(0); const handleClick = () => { setTimeout(() => { console.log(count); }, 1000); }; What will this log? 🤔 It logs the value of count at the time handleClick was created This is why we sometimes face “stale closure” issues ⚠️ Why this matters? Understanding closures helps you: ✔ Debug tricky bugs ✔ Avoid stale state issues ✔ Write better React logic Tip for Interview ⚠️ Don’t just define closures Explain how they behave in React That’s what interviewers look for Good developers use React. Great developers understand how it works under the hood. 🚀 #ReactJS #JavaScript #Closures #FrontendDeveloper #WebDevelopment #ReactInterview #CodingInterview #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚨 Senior JavaScript Interview — Not for Beginners At senior level, you’re not evaluated on syntax. You’re evaluated on decisions, trade-offs, and failure handling. Let’s test that 👇 🧠 𝟭. 𝗖𝗼𝗻𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝘆 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 You need to process 1,000 API requests —but your backend can only handle 10 concurrent requests. How would you design this? (No libraries by default — think patterns.) ⚡ 𝟮. 𝗥𝗮𝗰𝗲 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻 𝗦𝗰𝗲𝗻𝗮𝗿𝗶𝗼 Two API calls update the same state: 𝘴𝘦𝘵𝘜𝘴𝘦𝘳(𝘥𝘢𝘵𝘢𝘍𝘳𝘰𝘮𝘈𝘗𝘐1); 𝘴𝘦𝘵𝘜𝘴𝘦𝘳(𝘥𝘢𝘵𝘢𝘍𝘳𝘰𝘮𝘈𝘗𝘐2); Sometimes UI shows stale data. Why does this happen? How do you fix it *reliably*? 🔥 𝟯. 𝗠𝗲𝗺𝗼𝗿𝘆 𝗟𝗲𝗮𝗸 𝗶𝗻 𝗣𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 Your app memory keeps increasing over time. No crashes. Just slow degradation. Where do you start debugging? (Be specific — not “check code.”) 🧩 𝟰. 𝗥𝗲𝗻𝗱𝗲𝗿𝗶𝗻𝗴 𝗦𝘁𝗿𝗮𝘁𝗲𝗴𝘆 You have a page with: • 20k rows • Filters • Real-time updates How would you design rendering for performance? (Think beyond “use pagination”) 🚀 𝟱. 𝗦𝘆𝘀𝘁𝗲𝗺 𝗗𝗲𝘀𝗶𝗴𝗻 𝗧𝗵𝗶𝗻𝗸𝗶𝗻𝗴 You’re building a large frontend app used by 1M+ users. How do you decide: • What goes to frontend vs backend? • What stays in global state vs local state? • How to avoid tight coupling? 🎯 A senior engineer doesn’t just write code. They: • Prevent failures • Design for scale • Think in trade-offs 💬 Drop your answers below. I’ll break down *real production-level answers* in the next post. Follow to not miss it 👇 #javascript #frontend #seniorengineer #systemdesign #techinterview #DAY83
To view or add a comment, sign in
-
🚨 React Interview Question That Confuses 90% Developers Let’s test your React fundamentals 👇 import { useState } from "react"; export default function App() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); setCount(count + 2); setCount(count + 3); console.log(count); } return ( <> <h1>{count}</h1> <button onClick={handleClick}>Click</button> </> ); } 👉 What will be the output? 1️⃣ Console output? 2️⃣ Final UI value? ⚡ Bonus: Why doesn’t it become 3 (or even 6)? 👇 Think before reading the answer 👇 — — — — — — — — — — — — ✅ Answer Console → 0 UI → 3 🧠 Why? React batches state updates and treats them as async. All setCount calls use the same stale value (count = 0). So internally: 0 + 1 = 1 0 + 2 = 2 0 + 3 = 3 ✅ (last update wins) 🔥 Correct way (if you want cumulative updates): setCount(prev => prev + 1); setCount(prev => prev + 1); setCount(prev => prev + 1); 👉 Now React updates sequentially → Final = 3 💬 Takeaway: • State updates are async • React batches updates • Avoid stale values • Use functional updates when chaining Did you get it right? 👀 #ReactJS #FrontendInterview #JavaScript #ReactHooks #FrontendDeveloper
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