💥Can You Guess the Output(Advanced JavaScript Edition) 🚀 Output Challenge for JavaScript Developers! Let’s test how deep your JS fundamentals really go 👇 What will be the output of this code? (No AI, no console — just brain + logic 🧠) const obj = { name: 'Rohit', greet() { console.log(`Hello, ${this.name}`); }, delayedGreet() { setTimeout(this.greet, 1000); }, }; obj.delayedGreet(); 🧩 Think before you scroll away — Most developers get this wrong in live interviews (even senior ones). 👉 Drop your answer below in the comments Explain why it happens, not just what happens. Let’s see how many get it right 🔥 #JavaScript #Frontend #WebDevelopment #React #Nextjs #CleanCode #DeveloperCommunity #MachineCodingRound #InterviewPreparation
JavaScript Output Challenge: Guess the Result
More Relevant Posts
-
🚀 JavaScript Records & Tuples - The Future of Immutable Data! 🧠 Modern JavaScript keeps evolving - and Records & Tuples are one of the most exciting new additions coming to the language! 💥 💡 What are they? They’re immutable versions of objects and arrays - meaning once created, they can’t be changed. Think of them as “frozen” data structures that improve safety and predictability. 👉 Example: const user = #{ name: "John", age: 27 }; const skills = #["React", "JS", "RN"]; Both user and skills are now immutable — no accidental mutations! 🔒 ✅ Why it matters: • Prevents unwanted side effects • Improves performance in large apps • Perfect for functional programming • Makes debugging easier The future of JS is getting more predictable and developer-friendly — and this is a big step in that direction! 🚀 #JavaScript #WebDevelopment #ReactNative #ReactJS #Frontend #TypeScript #CodingTips #ImmutableData #ESNext #ModernJavaScript #Developer #linkedin #typeScript
To view or add a comment, sign in
-
🚀 Creating Regular Expressions: Literal and Constructor (JavaScript) JavaScript provides two primary ways to create regular expressions: literal notation and the `RegExp` constructor. Literal notation uses forward slashes (`/pattern/flags`) and is preferred for constant patterns because it's compiled once when the script loads. The `RegExp` constructor (`new RegExp('pattern', 'flags')`) is useful when the pattern is dynamic or comes from a variable. Both methods achieve the same result but differ in performance and flexibility. 💪 Never skip your daily dose of learning — it compounds! ⚡ 💡 Knowledge at scale — 10,000+ concepts, 4,000+ articles, 12,000+ quiz questions. All AI-personalized! 👇 Links available in the comments! #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
👉 Think You’re Copying Objects Correctly in JavaScript? Think Again! Many developers (even experienced ones) get unexpected results when working with object copies, leading to sneaky bugs! Let’s break it down 👇 🧠 Shallow vs Deep Copy in JavaScript A shallow copy only copies the first layer of the object, while a deep copy duplicates everything, including nested objects. 💡 Why it matters: Understanding these differences is crucial when managing state in frameworks like React or Vue. A shallow copy can cause unwanted side effects, especially when updating complex data structures. Choosing the right method (like structuredClone, JSON.parse(JSON.stringify()), or libraries like lodash.cloneDeep) ensures cleaner, more predictable code. 🤔 Your turn: How do you usually handle object copying in your projects? Do you prefer built-in methods or libraries? Let’s discuss! #JavaScript #FrontendDevelopment #WebDevelopment #CodingTips #ReactJS
To view or add a comment, sign in
-
-
🚀 Understanding the Iterator Pattern (JavaScript) The Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. It encapsulates the traversal logic, allowing clients to iterate over different types of collections in a uniform way. This promotes loose coupling between the client and the collection. Iterators are essential for working with data structures and algorithms. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
🚀 Iterating Over Arrays: for loops (JavaScript) The `for` loop is a fundamental way to iterate over the elements of an array. It allows you to access each element in the array sequentially using its index. You initialize a counter variable, specify a condition for continuing the loop (usually based on the array's length), and increment the counter after each iteration. This provides precise control over the iteration process. 🎓 The only bad learning day is a day without learning! 🔥 Level up your skills — 10k+ concepts, 4k+ articles, 12k+ questions. AI does the heavy lifting! 👇 Links available in the comments! #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
🚀 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗦𝗲𝗿𝗶𝗲𝘀 – 𝗗𝗮𝘆 𝟮: 𝗧𝗵𝗲 𝗣𝗼𝘄𝗲𝗿 𝗼𝗳 ‘𝘁𝗵𝗶𝘀’ 𝗞𝗲𝘆𝘄𝗼𝗿𝗱 🧠 Concept Focus: Understanding this in JavaScript is a game-changer — it can either make or break your logic! 💡 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐭𝐡𝐢𝐬? this refers to the object that is executing the current function. But its value depends on how the function is called, not where it’s defined. 🔍 𝐄𝐱𝐚𝐦𝐩𝐥𝐞𝐬: 1️⃣𝐆𝐥𝐨𝐛𝐚𝐥 𝐒𝐜𝐨𝐩𝐞:- console.log(this); 𝐨𝐮𝐭𝐩𝐮𝐭:- // In browser → Window // In Node.js → {} 2️⃣ 𝐈𝐧𝐬𝐢𝐝𝐞 𝐚𝐧 𝐎𝐛𝐣𝐞𝐜𝐭 👉const user = { name: "Alex", greet() { console.log(this.name); }, }; user.greet(); 𝐨𝐮𝐭𝐩𝐮𝐭- Alex 3️⃣𝐈𝐧𝐬𝐢𝐝𝐞 𝐚 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 👉function show() { console.log(this); } show(); 𝗼𝘂𝘁𝗽𝘂𝘁:- undefined (in strict mode) 4️⃣ 𝐖𝐢𝐭𝐡 𝐀𝐫𝐫𝐨𝐰 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 const obj = { name: "Mia", greet: () => { console.log(this.name); }, }; obj.greet(); 𝗼𝘂𝘁𝗽𝘂𝘁 undefined (arrow functions don't bind `this`) 5️⃣𝐔𝐬𝐢𝐧𝐠 𝐜𝐚𝐥𝐥, 𝐚𝐩𝐩𝐥𝐲, 𝐛𝐢𝐧𝐝 function sayHello() { console.log(`Hello, ${this.name}`); } const person = { name: "Sam" }; sayHello.call(person); 𝗼𝘂𝘁𝗽𝘂𝘁- Hello,Sam ⚡ 𝐐𝐮𝐢𝐜𝐤 𝐓𝐢𝐩 👉 Arrow functions inherit this from their surrounding scope. 👉 Regular functions define their own this based on how they’re called. 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧: Q: What is the difference between this in a regular function vs. an arrow function? ✅ 𝐀𝐧𝐬𝐰𝐞𝐫 : Regular functions have their own this (depends on the caller). Arrow functions capture this from their surrounding lexical scope. 🤔🤔🤔 𝐍𝐞𝐱𝐭 𝐏𝐨𝐬𝐭 :- 𝐇𝐨𝐰 𝐭𝐨 𝐛𝐢𝐧𝐝 𝐭𝐡𝐞 𝐯𝐚𝐥𝐮𝐞 𝐨𝐟 '𝐭𝐡𝐢𝐬' ? 💬 𝐘𝐨𝐮𝐫 𝐓𝐮𝐫𝐧 : Have you ever been confused by this in JavaScript? Comment your favorite tricky example 👇 #JavaScript #InterviewSeries #WebDevelopment #Frontend #Coding #Angular #React #100DaysOfCode
To view or add a comment, sign in
-
🚀 Understanding Lexical Scoping & Closures in JavaScript If you really want to master JavaScript, you must understand Lexical Scoping and Closures — two powerful concepts that define how your code thinks and remembers. 💭 🧠 Lexical Scoping It determines where your variables are accessible. In JavaScript, every function creates its own scope — and functions can access variables from their own scope and the scope where they were defined, not where they were called. That’s why JavaScript is said to be lexically scoped — the position of your code during writing decides what variables a function can access. 🔒 Closures A closure is when a function “remembers” the variables from its outer scope even after that outer function has returned. It’s what allows inner functions to keep their private data alive, long after the parent function finishes executing. Closures enable data privacy, state preservation, and function factories — powering everything from event handlers to module patterns. 🧩 Example Insight: In a nested function setup, if inner() still accesses count after outer() has returned, you’re witnessing closure magic in action! 💡 Pro Tip: Closures are not just theory — they’re behind: Private variables in JavaScript Real-time counters and timers Function currying React hooks (like useState!) Mastering them transforms you from writing code… to understanding how JavaScript actually works under the hood. 📚 Why It Matters Lexical scoping defines where you can access data. Closures define how long that data can live. Together, they form the core foundation of functional programming and modern frameworks like React and Node.js. 💬 Question for You Have you ever used closures intentionally in your projects — maybe for a counter, a module, or a hook? Share your example below 👇 Let’s help more devs understand these hidden superpowers of JS! 🔖 Hashtags #JavaScript #WebDevelopment #Closures #LexicalScope #FrontendDevelopment #Coding #JSConcepts #WebDevCommunity #LearnToCode #CodeNewbie #ProgrammingTips #100DaysOfCode #DeveloperJourney #SaadArif
To view or add a comment, sign in
-
-
Day-4 I Learned: JavaScript Callbacks, Promises & Async/Await Today, I took a deep dive into how JavaScript handles async tasks like fetching data, calling APIs, or reading files — without freezing the UI or blocking the event loop. Here’s what I learned 👇 ⚡ Callbacks – My first step into async programming. Simple but can quickly be come messy when nested too deep (a.k.a. callback hell). ⚡ Promises – A cleaner and more structured approach using .then() and .catch(). It made error handling and code readability much better. ⚡ Async / Await – The game changer. Writing asynchronous code that looks synchronous, making it easier to debug and maintain. 💡 Key Takeaway: Mastering these three — Callbacks → Promises → Async/Await — is essential for anyone working with JavaScript, Node.js, or MERN Stack. It’s the foundation of building smooth, efficient, and scalable web applications. #JavaScript #AsyncAwait #Promises #Callbacks #WebDevelopment #NodeJS #MERNStack #SoftwareEngineering #CodingJourney #Developers #LearnToCode #100DaysOfCode #Frontend #Backend #FullStack
To view or add a comment, sign in
-
-
🚀 Understanding JavaScript Objects as Hash Maps JavaScript objects, in their basic form, function as hash maps or dictionaries. They store data in key-value pairs, where keys are typically strings and values can be any JavaScript data type. This allows for efficient retrieval of values based on their associated keys. Unlike arrays, objects are unordered. The flexibility of objects makes them ideal for representing complex data structures and configurations. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
💡 Day 8/50 – Mastering JavaScript’s Subtle Behaviors 🚀 In JavaScript, sometimes the hardest bugs aren’t syntax errors — they’re “Wait… why did that happen?” moments 😅 Today’s Day 8 questions were built around 3 such moments that every developer faces: --- 🧬 1️⃣ Prototype Inheritance — The Hidden Chain When you create an object using Object.create(), it doesn’t copy properties from the parent… it links to it. That means if a property isn’t found in the child, JavaScript looks up the prototype chain to find it. 👉 This “lookup behavior” often confuses devs who expect a fresh, independent copy. So the next time you’re debugging unexpected data access, remember — It might not be your object, it might be its prototype! --- 🧠 2️⃣ The Mystery of Double .bind() You might think rebinding a function twice changes its context again. But nope! Once you bind a function in JavaScript, it’s permanently bound. Calling .bind() again has no effect — the context (the value of this) stays fixed to the first bind. 💡 Why? Because bind() returns a new function with the this value locked in forever. --- 🧩 3️⃣ Type Coercion + Function Conversion Ever tried adding a function to a string like add + "text"? JavaScript doesn’t crash — it converts your function to a string using its internal toString() method! The result isn’t math; it’s a combination of type coercion and string representation. This is one of those delightful quirks that makes JS both fun and… slightly unhinged 😄 --- 📽️ Watch Day 8 Reel: https://lnkd.in/gBHYWgyi Because once you understand the why, no interviewer can trick you again 😉 #JavaScript #FrontendDevelopment #WebDevelopment #JSInterviewQuestions #CodingChallenge #TechLearning #SoftwareEngineering #Techsharingan #Developers
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
"This" keyword basically depends on the way functions(lets not talk about arrow functions😭) are called. Here setTimeout basically takes the callback and store it somewhere and call that callback after timer runs out. When the call happens, its called at global(global execution context) level. And since there we dont have name, it prints 'Hello Undefined'. To fix this issue, we can bind greet function with this of delayedGreet which has name pointing to 'rohit'. Something like below. delayedGreet() { setTimeout(this.greet.bind(this), 1000); },