Quick JS Brain Teaser: What happens when you have return statements in try, catch, AND finally blocks? function testReturn() { try { return "try"; } catch (e) { return "catch"; } finally { return "finally"; } } console.log(testReturn()); What will be logged to the console? A) "try" B) "catch" C) "finally" D) undefined Does this match your expectations? Drop your answer and explain why! #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
JavaScript Try Catch Finally Return Statement
More Relevant Posts
-
Quick JS Brain Teaser: What will be the output of this code? async function test() { console.log('1'); setTimeout(() => { console.log('2'); }, 0); await Promise.resolve(); console.log('3'); setTimeout(() => { console.log('4'); }, 0); console.log('5'); } test(); console.log('6'); A) 1, 6, 3, 5, 2, 4 B) 1, 3, 5, 6, 2, 4 C) 1, 6, 2, 3, 5, 4 D) 1, 2, 3, 4, 5, 6 Drop your answer in the comments and explain why! Does this match your expectations for execution context questions? #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
To view or add a comment, sign in
-
Quick JS Brain Teaser: What will be the output order when this code executes? console.log(1); console.log(2); setTimeout(() => console.log(3)); Promise.resolve().then(() => setTimeout(() => console.log(4))); Promise.resolve().then(() => console.log(5)); new Promise(() => console.log(6)); console.log(7); Drop your answer in the comments and explain the event loop execution order behind your choice! Let's see who truly understands. #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
To view or add a comment, sign in
-
Quick JS Brain Teaser: What will be the output of this code? console.log('Start'); setTimeout(() => { console.log('Timeout'); }, 0); Promise.resolve() .then(() => console.log('Promise 1')) .then(() => console.log('Promise 2')); console.log('End'); Options: A) Start → End → Timeout → Promise 1 → Promise 2 B) Start → End → Promise 1 → Promise 2 → Timeout C) Start → Promise 1 → Promise 2 → End → Timeout D) Start → Timeout → Promise 1 → Promise 2 → End What's your answer? #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
To view or add a comment, sign in
-
Ever tried reading a property that doesn’t exist in JavaScript? No crash. No error. Just… undefined 😄 Most of us do this: if (user.noSuchProperty === undefined) { ... } Works 99% of the time. Until it doesn’t. let obj = { test: undefined }; console.log(obj.test); // undefined console.log("test" in obj); // true ← surprise! The property exists — it just happens to hold undefined. That tiny difference is exactly why the in operator exists. Have you ever been bitten by this gotcha? Or do you still prefer === undefined in everyday code? #JavaScript #CodingTips #WebDevelopment
To view or add a comment, sign in
-
💡 JavaScript Event Bubbling vs Capturing — a common misconception Ever clicked an element and expected 6 console logs, but only got 3? You’re not crazy — this is a classic DOM events gotcha. 👉 Key insight: Events always go through both capturing and bubbling phases, but listeners only fire in the phase they’re registered for. addEventListener('click', handler, true) That true means: ➡️ “Listen only during the capturing phase” So if you register: 3 capture listeners 0 bubble listeners You’ll see 3 logs, not 6 — even though bubbling did happen. To get all 6 logs, you must explicitly register both: capture listeners (true) bubble listeners (default) 🧠 Mental model that sticks: Capture = top → down Bubble = target → up No listener = no log Understanding this saves hours of debugging... #JavaScript #WebDevelopment #Frontend #DOM #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
🕵️The Event Loop continuously monitors the Call Stack. When the stack becomes empty, it first drains the entire Microtask Queue (e.g., Promises), then executes a single Macrotask (e.g., setTimeout), and repeats the cycle indefinitely. This priority model ensures microtasks complete before the next rendering or timer execution, maintaining deterministic async behavior. 🔁⚙️ #JavaScript #EventLoop #AsyncJavaScript #CallStack #Microtasks #Macrotasks
To view or add a comment, sign in
-
-
With console.time(), you can measure the performance of your code with precision. This simple method allows you to track how long a block of code takes to execute, enabling you to identify bottlenecks and optimize for speed. Transform your code from functional to efficient. Start timing your functions today and unlock the secrets to scalable performance! ⚡️ #JavaScript #Performance #Optimization"
To view or add a comment, sign in
-
-
Quick JS Brain Teaser: What happens when you try to add a property to a primitive string value? let str = "hello"; str.customProp = "world"; console.log(str.customProp); Options: A) "world" B) undefined C) TypeError D) "helloworld" Does this match your expectations? Drop your answer in the comments and explain the autoboxing behavior! Let's discuss how JavaScript handles primitives vs objects. #JavaScript #JavaScriptInterviewQuestion #JavaScriptFundamentals
To view or add a comment, sign in
-
🚀 Closures finally clicked for me! While revisiting JavaScript fundamentals, I spent time deeply understanding Closures — and it changed how I see functions. 💡 A closure is when an inner function remembers variables from its outer function — even after the outer function has executed. Example: function counter() { let count = 0; return function () { count++; return count; }; } const c = counter(); console.log(c()); // 1 console.log(c()); // 2 Even though counter() has finished executing, the inner function still remembers count. That memory is called a closure. 🔑 Why closures matter: • Helps keep data private • Used in counters, timers, modules • Very common in React & event handlers #JavaScript #Closures #FrontendDevelopment #WebDevelopment
To view or add a comment, sign in
-
⚡ React Performance = Render Discipline Most React performance issues aren’t about heavy logic. They’re about components rendering more than they should. Common causes: • State too high in the tree • Inline functions breaking memoization • Overusing useEffect • Rendering large lists without virtualization Key shift for me: 👉 Every render has a cost. Profile first with React DevTools, then optimize intentionally. Clean data flow > clever hacks. #React #FrontendPerformance #WebDevelopment #JavaScript
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