🧠 Developer Challenge – Can You Solve This in 10 Seconds? Many developers fail this simple JavaScript logic test during interviews. What will be the output of this code? 👇 for (var i = 0; i < 3; i++) { setTimeout(() => { console.log(i); }, 1000); } 🧠 Options: A️⃣ 0 1 2 B️⃣ 3 3 3 C️⃣ 0 0 0 D️⃣ 1 2 3 👇 Comment your answer before reading the explanation. . . . ✅ Answer: B️⃣ 3 3 3 💡 Reason: var is function-scoped, not block-scoped. By the time setTimeout runs, the loop has already finished and i becomes 3. So the callback prints 3 three times. 🔧 Correct Version Using let: for (let i = 0; i < 3; i++) { setTimeout(() => { console.log(i); }, 1000); } Output: 0 1 2 📌 Learning: Understanding JavaScript scope and closures is crucial for writing predictable asynchronous code. 💬 Did you get it right? Comment YES or your answer below! #JavaScript #Angular #FrontendDevelopment #CodingChallenge #SoftwareEngineering #Developers #TechLearning
JavaScript Scope Challenge: Can You Solve It?
More Relevant Posts
-
💡 Interview Question: Understanding Data Types in JavaScript Recently came across an interesting question that tests your fundamental 👇 let a = ''; let b = false; let c = 0; let d = null; let e; let f = {}; let g = []; if (!a) console.log('1') // similarly check for b, c, d, e, f, g 👉 Question: What will be printed in the console for each variable? 🧠 Concept Tested: Truthy vs Falsy values in JavaScript 📌 Falsy values in JS: '' (empty string) false 0 null undefined NaN 📌 Truthy values: {} (empty object) [] (empty array) ✅ Output: 1 2 3 4 5 (Only for a, b, c, d, e → because they are falsy) 🚫 Nothing will be printed for: f = {} g = [] (because they are truthy) 🎯 Key Takeaway: Even empty objects and arrays are considered truthy in JavaScript — a common interview trap! #JavaScript #FrontendDevelopment #WebDevelopment #CodingInterview #InterviewQuestions #Programming #Developers #TechTips #LearnToCode
To view or add a comment, sign in
-
🚀 Boost Your JavaScript Skills with This Super Simple Cheat Sheet! New to JS or prepping for interviews? Nail these basics first – they'll make coding way easier! 😎 • Variables: Use let for changeable stuff, const for fixed values. Easy peasy! 🔄 • Data Types: Primitives (numbers, strings) vs. non-primitives (objects, arrays). Know the difference! 📊 • Control Flow: if/else, switch, ternary (condition ? true : false). Quick decisions!⚡ • Array Magic: map() transforms, filter() picks, reduce() sums, forEach() loops. Game-changers! 🪄 • Functions: Declare with function name() {}, express as const fn = () => {}, or arrow style. Super flexible! ➡️ • DOM & Events: Grab elements with document.getElementById(), add listeners like addEventListener(). Make pages alive! 🎉 • ES6+ Goodies: Destructure {name} = obj, spread ...array, promises, async/await. Modern power! ✨ Master these, and JS frameworks + projects will feel simple. Save it, share it, level up! 💪 #JavaScript #WebDevelopment #CodingTips #LearnToCode #FrontendDev #Programming #TechTips #JavaScriptCheatSheet
To view or add a comment, sign in
-
🔥 Interview Question That Looks Easy… But Isn’t Let’s see how sharp your JavaScript fundamentals are 👇 What will be the output of this code? console.log(1 < 2 < 3); console.log(3 > 2 > 1); 🧠 Options: A️⃣ true true B️⃣ true false C️⃣ false true D️⃣ false false 👇 Drop your answer before checking the explanation. . . . ✅ Correct Answer: B️⃣ true false 💡 Explanation 👉 1 < 2 < 3 1 < 2 → true true < 3 → 1 < 3 → true 👉 3 > 2 > 1 3 > 2 → true true > 1 → 1 > 1 → false 📌 Learning: JavaScript evaluates expressions left to right and performs type coercion, converting true → 1 and false → 0. ⚠️ This can easily cause hidden logical bugs in real applications. 💬 Did you get it right? Comment “Got it” or your answer 👇 #JavaScript #FrontendDevelopment #Angular #CodingChallenge #Developers #TechInterview #LearningInPublic
To view or add a comment, sign in
-
📘 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐌𝐨𝐝𝐮𝐥𝐞 (𝐁𝐚𝐬𝐢𝐜) -> Save this checklist, I hope it will be of great use in your next interview revision! 👇 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 2: 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 11. 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐮𝐧𝐝𝐞𝐟𝐢𝐧𝐞𝐝? -> JavaScript's default value is when nothing is assigned. This is a default behavior of JavaScript. If you have declared a variable (var age;) but have not given a value, JavaScript will automatically call it undefined. 12. 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐍𝐚𝐍? -> Not a Number — invalid number result. This comes when you do something wrong while doing math. Example: If you multiply your name by 10 ("Sohan" * 10), JavaScript will say—brother, this is not a number, so the output will be NaN. 13. 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐧𝐮𝐥𝐥? -> Intentionally assigning an empty value. You do this intentionally. When you want a variable to be empty now, and later the data will come, then you set age = null; yourself. 14. 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐜𝐨𝐧𝐜𝐚𝐭𝐞𝐧𝐚𝐭𝐢𝐨𝐧? -> Adding two strings or concatenating two texts. For example: "Hello " + "World". 15. 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐈𝐧𝐟𝐢𝐧𝐢𝐭𝐲? -> When a number is divided by 0. 50/0 result infinity. 16.𝐇𝐨𝐰 𝐭𝐨 𝐚𝐬𝐬𝐢𝐠𝐧 𝐝𝐚𝐭𝐚 𝐭𝐨 𝐚 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞? / 𝐇𝐨𝐰 𝐭𝐨 𝐚𝐬𝐬𝐢𝐠𝐧 𝐚 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞 𝐝𝐚𝐭𝐚? -> let x; x = 10; 17. 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞 𝐢𝐬 𝐩𝐫𝐢𝐦𝐢𝐭𝐢𝐯𝐞 𝐨𝐫 𝐧𝐨𝐧-𝐩𝐫𝐢𝐦𝐢𝐭𝐢𝐯𝐞? -> Primitive (stores single data of single value) #DotNet #AspNetCore #MVC #FullStack #SoftwareEngineering #ProgrammingTips #DeveloperLife #LearnToCode #JavaScript #JS #JavaScriptTips #JSLearning #FrontendDevelopment #WebDevelopment #CodingTips #CodeManagement #DevTools
To view or add a comment, sign in
-
-
"Would you be able to answer these frontend questions under pressure? 🧠 I was recently tested on these exact concepts. Some were easy, some were tricky, but all of them are essential. How many of these can you solve? 👇" 1️⃣ How does hoisting behave with var, let, and const in JavaScript? 2️⃣ What exactly is the JavaScript Event Loop? 3️⃣ How does JavaScript handle asynchronous tasks internally? 4️⃣ What is the window object in JavaScript? 5️⃣ What is the difference between a class and a constructor? 6️⃣ What are Event Bubbling and Event Capturing? Which one is false by default? 7️⃣ What is the Browser Object Model (BOM)? 8️⃣ What is an Immediately Invoked Function Expression (IIFE)? 9️⃣ Why is JavaScript called a scripting language? 🔟 What is the difference between formal parameters and actual parameters? 💡 If you're learning JavaScript or preparing for interviews, try answering these in the comments! #javascript #webdevelopment #frontend #coding #programming #developers #learning #coding #learning #developers
To view or add a comment, sign in
-
Complete JavaScript CheatSheet, Full Guide When you're building projects or preparing for interviews, you often forget small things like: Which method filters arrays? How to manipulate strings? Which DOM function selects elements? So I’m sharing a 𝐜𝐨𝐦𝐩𝐥𝐞𝐭𝐞 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐂𝐡𝐞𝐚𝐭 𝐒𝐡𝐞𝐞𝐭 that covers the most useful concepts developers use daily. 𝗜𝘁 𝗶𝗻𝗰𝗹𝘂𝗱𝗲𝘀: 𝗔𝗿𝗿𝗮𝘆 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 • map() • filter() • reduce() • push() / pop() • slice() / splice() 𝗦𝘁𝗿𝗶𝗻𝗴 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 • charAt() • includes() • replace() • split() • trim() 𝗗𝗢𝗠 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 • getElementById() • querySelector() • createElement() 𝗖𝗼𝗻𝘀𝗼𝗹𝗲 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 • console.log() • console.error() • console.warn() 𝗕𝗿𝗼𝘄𝘀𝗲𝗿 𝗢𝗯𝗷𝗲𝗰𝘁𝘀 • Window Object • Navigator Object • Location Object • History Object These concepts are commonly used in 𝐫𝐞𝐚𝐥 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐝𝐞𝐯𝐞𝐥𝐨𝐩𝐦𝐞𝐧𝐭 𝐚𝐧𝐝 𝐝𝐞𝐛𝐮𝐠𝐠𝐢𝐧𝐠. If you're learning 𝐖𝐞𝐛 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐦𝐞𝐧𝐭, 𝐅𝐫𝐨𝐧𝐭𝐞𝐧𝐝, 𝐨𝐫 𝐩𝐫𝐞𝐩𝐚𝐫𝐢𝐧𝐠 𝐟𝐨𝐫 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰𝐬, this can be a very useful quick reference. 𝗖𝗼𝗻𝗻𝗲𝗰𝘁 with me M. WASEEM ♾️ Credit goes to Cloudaffle Save this post so you can revisit it when coding. #JavaScript #WebDevelopment #FrontendDevelopment #Coding #Programming #SoftwareEngineering #LearnToCode #Developers
To view or add a comment, sign in
-
⚡ Developer Brain Teaser – Only Experienced Developers Notice This What will be the output of this JavaScript code? 👇 console.log(typeof null); 🧠 Options A️⃣ "null" B️⃣ "object" C️⃣ "undefined" D️⃣ "number" 👇 Comment your answer before scrolling further. . . . ✅ Correct Answer: B️⃣ "object" 💡 Explanation In JavaScript: typeof null returns: "object" This is actually considered a historical bug in JavaScript that has existed since the first version of the language. Why? Internally, JavaScript represents values using type tags, and null was incorrectly tagged as an object. Because fixing it would break millions of existing applications, it has never been changed. 📌 Learning Point Even senior developers get surprised by JavaScript quirks. Understanding these edge cases helps during debugging, interviews, and writing reliable code. 💬 Did you know this already? Comment “Yes” or “Learned something new today” 👇 #JavaScript #FrontendDevelopment #Angular #CodingChallenge #Developers #TechLearning #SoftwareEngineering
To view or add a comment, sign in
-
🚀 JavaScript Function Types Explained (Simple & Clear Guide) Functions are the backbone of JavaScript. Mastering them helps you write cleaner, more efficient, and scalable code. Here are the key function types every developer should know: 🔹 Function Declarations – The standard and most widely used 🔹 Function Expressions – Useful for more control and flexibility 🔹 Arrow Functions (=>) – Modern, concise, and popular in React 🔹 Callback Functions – Essential for handling asynchronous operations 🔹 IIFE (Immediately Invoked Function Expression) – Executes immediately after definition 🔹 Higher-Order Functions – Functions that take or return other functions 💡 Understanding these concepts will boost your coding skills and help you perform better in technical interviews. 👉 Which function type do you use the most in your projects? Let’s discuss in the comments 👇 #JavaScript #WebDevelopment #Frontend #Coding #ReactJS #NodeJS #Programming #Interviews #Tips #Tricks
To view or add a comment, sign in
-
-
Headline: 🚀 Master Your Next JavaScript Interview: From Basic Logic to Advanced Architecture JavaScript is more than just syntax; it’s about understanding the engine under the hood. Whether you're a junior dev or a senior architect, these concepts consistently separate the prepared from the panicked. I’ve broken down the essential roadmap into three key pillars: 1️⃣ Basic Logic & Data Manipulation Can you manipulate data efficiently? Be ready for: Palindrome Checks and String Reversal. Removing duplicates using modern tools like Set. Algorithmic thinking with Recursion (Factorials/Fibonacci). 2️⃣ Functional Programming Power Do you understand how JS functions truly behave? Closures: How functions remember their lexical scope. Currying: Transforming multi-argument functions. Debounce & Throttle: Essential for performance-driven UI. 3️⃣ Advanced Architectural Concepts This is where the senior-level magic happens: The Event Loop: Understanding the Call Stack vs. Microtask Queue. Prototypal Inheritance: How objects inherit from one another. Async/Await & Promises: Mastering non-blocking operations. 💡 Pro-Tip: Don’t just memorize answers. Understand the why behind them. For example, knowing why let is hoisted differently than var shows you understand the Temporal Dead Zone. What’s the trickiest JavaScript question you’ve ever faced in an interview? Let’s discuss in the comments! 👇 #JavaScript #WebDevelopment #FrontendDeveloper #CodingInterview #Programming #SoftwareEngineering #TechInterview
To view or add a comment, sign in
-
-
🚀🔥 Mastering JavaScript String Methods & Real-Time Problems 🔥🚀 🚀Today I focused on strengthening my String fundamentals + problem-solving skills 💻🧠 ✨ What I Practiced: 🔹 Clean user input by removing unwanted spaces 🔹 Case-insensitive comparisons (real login scenarios) 🔹 Searching words inside strings 🔹 Extracting specific parts of strings (like usernames, substrings) 🔹 Converting data types (string ↔ number) 🔹 Working with arrays from strings 💡 Real-Time Use Cases I Solved: ✅ Email username extraction ✅ File type validation (.html check) ✅ Password masking using symbols ✅ Replacing spaces for URL-friendly strings ✅ Checking word existence in sentences 🧠 Logic-Based Problems Covered: 🔸 Reverse a string (without built-in methods) 🔸 Check palindrome 🔸 Count vowels in a string 🔸 Find frequency of characters 🔸 First repeating & non-repeating character 🔸 Remove duplicate characters 🔸 Check anagrams 🔸 String compression (aaabbc → a3b2c1) 🔸 Reverse case transformation (hELLO wORLD) 🔥 Key Learnings: ✔️ Strings are immutable (operations return new values) ✔️ Combining multiple methods is powerful ✔️ Logic building is more important than memorizing methods ✔️ Writing generic solutions is crucial for interviews #JavaScript #WebDevelopment #FrontendDeveloper #CodingJourney #ProblemSolving #DSA #LearningInPublic #CareerGrowth #TechJourney
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