FlashRevise

JavaScript Concepts

Core concepts and tricky parts of JavaScript.

Flashcards (4)
Manage the cards in this deck.
QuestionAnswerActions
What is a "closure" in JavaScript?A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function's scope from an inner function.
Explain the difference between `==` and `===`.`==` is the "loose equality" operator, which performs type coercion. `===` is the "strict equality" operator, which does not perform type coercion and checks for both value and type equality.
What is the `event loop`?The event loop is a mechanism that allows Node.js to perform non-blocking I/O operations despite the fact that JavaScript is single-threaded. It offloads operations to the system kernel whenever possible.
What does this code do? ```javascript console.log(1); setTimeout(() => console.log(2), 0); console.log(3); ```It logs `1`, then `3`, then `2`. This is because `setTimeout` schedules the function to run in a future turn of the event loop, after the current synchronous code has finished executing.