Welcome to Vanilla-JavaScript-Workshop Discussions! #40
-
👋 Welcome!We’re using Discussions as a place to connect with other members of our community. We hope that you:
To get started, comment below with an introduction of yourself and tell us about what you do with this community. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 8 replies
-
Anyone can start a conversion about this repository! |
Beta Was this translation helpful? Give feedback.
-
A closure is a function that remembers the variables from its outer scope even after the outer function has finished executing. This allows functions to maintain private variables. javascript const closureExample = outerFunction("Hello"); Closures are commonly used in data hiding, function factories, and event handlers. |
Beta Was this translation helpful? Give feedback.
-
const numbers = [1, 2, 3, 4]; // map // forEach // filter // reduce |
Beta Was this translation helpful? Give feedback.
-
What are Promises and how do they work? |
Beta Was this translation helpful? Give feedback.
-
A Promise is an object that represents an asynchronous operation with three possible states: |
Beta Was this translation helpful? Give feedback.
-
What is an event loop in JavaScript? |
Beta Was this translation helpful? Give feedback.
-
The Event Loop is a mechanism in JavaScript that ensures non-blocking execution of asynchronous code. It continuously monitors the Call Stack and the Task Queues, moving tasks from the queue to the stack when the stack is empty. This is crucial because JavaScript is single-threaded, meaning it can only execute one task at a time. How It Works: |
Beta Was this translation helpful? Give feedback.
-
What is await in JavaScript? |
Beta Was this translation helpful? Give feedback.
-
The await keyword is used inside an async function to pause execution until a Promise is resolved. It makes asynchronous code look and behave more like synchronous code, improving readability. How await Works:
} fetchData(); fetchData() starts executing, but await pauses at fetch(), allowing "Other work..." to execute. |
Beta Was this translation helpful? Give feedback.
-
The await keyword is used inside an async function to pause execution until a Promise is resolved. It makes asynchronous code look and behave more like synchronous code, improving readability. How await Works:
} fetchData(); fetchData() starts executing, but await pauses at fetch(), allowing "Other work..." to execute. |
Beta Was this translation helpful? Give feedback.
A closure is a function that remembers the variables from its outer scope even after the outer function has finished executing. This allows functions to maintain private variables.
javascript
Copy
Edit
function outerFunction(outerVariable) {
return function innerFunction(innerVariable) {
console.log(
Outer: ${outerVariable}, Inner: ${innerVariable}
);};
}
const closureExample = outerFunction("Hello");
closureExample("World"); // Output: Outer: Hello, Inner: World
Closures are commonly used in data hiding, function factories, and event handlers.