🧠 JavaScript Async/Await Challenge What will be the output? async function test() { console.log("1"); await Promise.resolve(); console.log("2"); } console.log("3"); test(); console.log("4"); Options: A) 3 1 2 4 B) 3 1 4 2 C) 1 3 4 2 D) 3 4 1 2 What do you think the output will be? 👀 #javascript #frontenddeveloper #webdevelopment #codingchallenge
JavaScript Async/Await Output Prediction
More Relevant Posts
-
🧠 JavaScript Async/Await Challenge What will be the output? async function test() { console.log("1"); await Promise.resolve(); console.log("2"); } console.log("3"); test(); console.log("4"); Options: A) 3 1 2 4 B) 3 1 4 2 C) 1 3 4 2 D) 3 4 1 2 #javascript #frontenddeveloper #webdevelopment #codingchallenge
To view or add a comment, sign in
-
🚀 Day 23 - Poll answer & Explanation 💡 **JavaScript Event Loop Explained (Simple & Clear)** ```javascript console.log('S'); Promise.resolve().then(() => console.log('P1')); setTimeout(() => console.log('T1'), 0); Promise.resolve().then(() => console.log('P2')); setTimeout(() => console.log('T2'), 0); console.log('E'); Output: S E P1 P2 T1 T2 ``` 🔹 **Explanation:** * `S` and `E` run first → synchronous code (call stack) * `P1`, `P2` → microtasks (Promises) → run next * `T1`, `T2` → macrotasks (setTimeout) → run last 👉 Microtasks always execute before macrotasks in the event loop. #JavaScript #ReactJS #WebDevelopment #Coding #FrontendDeveloper #InterviewPrep
To view or add a comment, sign in
-
Day 1 — Reverse a String (JavaScript) Problem Write a function that reverses a given string. Example Input: "hello" Output: "olleh" Approach Start from the last character of the string and iterate backwards. Keep adding each character to a new string until the loop finishes. Code function reverseString(str){ let reversed = "" for(let i = str.length - 1; i >= 0; i--){ reversed += str[i] } return reversed } console.log(reverseString("hello")) What I Learned Basic string traversal and how iteration works from the end of a string. #javascript #frontenddeveloper #codingpractice #dsa
To view or add a comment, sign in
-
-
🚀 Day 2/30 – JavaScript Challenge LeetCode Problem: 2620 – Counter Today I learned about one of the most important concepts in JavaScript Closures. 🔹 Concept Explained: The inner function remembers the variable number even after the outer function has finished execution. This is called a closure. 🔹 Key Learnings: ✅ Closures help maintain state without global variables ✅ Useful in counters, ID generators, and real-world applications ✅ number++ returns the current value, then increments it #Leetcode #Day2 #JavaScript #Developers #Frontend
To view or add a comment, sign in
-
-
learned optional chaining in react today. making: IPL project 🏏 issue faced: accessing nested objects like "object.object.object" fix/learned: optional chaining ("?.") to avoid crashes & undefined errors small thing, big sanity save. #reactjs #webdev #buildinpublic #javascript
To view or add a comment, sign in
-
-
JavaScript Event Loop is simple… until it’s not ⚡ Most developers use setTimeout and Promise daily but don’t fully understand what happens behind the scenes. Let’s break it down 👇 💡 JavaScript is single-threaded 👉 Only one thing runs at a time ⚡ Execution order: Synchronous code (Call Stack) Microtasks (Promises, queueMicrotask) Macrotasks (setTimeout, setInterval, DOM events) 👉 Then the loop repeats 📌 Priority: Synchronous → Microtasks → Macrotasks 🧠 Example: console.log(1); setTimeout(() => console.log(2), 0); Promise.resolve().then(() => console.log(3)); console.log(4); ✅ Output: 1 → 4 → 3 → 2 🔥 Why this matters: • Debug async issues faster • Avoid unexpected bugs • Write better React logic #JavaScript #FrontendDeveloper #ReactJS #CodingTips #WebDevelopment
To view or add a comment, sign in
-
💡Difference Between State and Props in React 👉 Props → Passed from parent to child (read-only) 👉 State → Managed inside the component (mutable) Simple rule I follow : Props = external data State = internal data Understanding this made React much clearer for me 👆 #reactjs #javascript #frontenddeveloper #webdevelopment
To view or add a comment, sign in
-
Day 5/100 of JavaScript Today’s Topic: Closures in JavaScript A closure is created when a function remembers variables from its outer scope even after that outer function has finished execution Example: function outer() { let count = 0; return function inner() { count++; return count; }; } const counter = outer(); counter(); // 1 counter(); // 2 Here, the "inner" function forms a closure over the "count" variable. Even though "outer()" has finished execution, "count" is preserved. Key understanding: Closures help in maintaining state and also enable data privacy by restricting direct access to variables #Day5 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
#js #4 **typeof operator** The typeof keyword in JavaScript is an operator that returns a string describing the data type of a value or variable. It’s widely used to check types at runtime, especially in dynamic code. Example: const firstName= 'Rohit' console.log(typeof(firstName)) //string const age = 20; console.log(typeof(age)) //number const isEligible = true console.log(typeof(isEligible)) //boolean #Javascript #ObjectOrientedProgramming #SoftwareDevelopment
To view or add a comment, sign in
-
Stop using delete to remove Array elements! 🛑 If you think the answer to the code below is 3, you're falling for a classic JavaScript trap. let numArr = [1, 2, 3, 4]; delete numArr[2]; Console.log(numArr.length) #JavaScript #WebDevelopment #CodingTips #SoftwareEngineering #FrontendDev #CleanCode
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