Yes Flashcards
(67 cards)
What is the difference between var
, let
, and const
?
var
is function-scoped and hoisted; let
and const
are block-scoped. const
cannot be reassigned.
What is a closure in JavaScript?
A closure is a function that remembers its outer scope even after the outer function has finished executing.
Explain the difference between ==
and ===
.
==
checks for value equality with type coercion, while ===
checks for both value and type equality.
What is the event loop?
It’s the mechanism that handles asynchronous operations by placing callbacks in the queue and executing them after the main call stack is clear.
What are arrow functions and how do they differ from regular functions?
Arrow functions use a shorter syntax and do not have their own this
context—they inherit it from the parent scope.
How does this
behave in JavaScript?
this
refers to the object that is calling the function, and behaves differently in strict mode, arrow functions, and event handlers.
What is hoisting?
Hoisting is JavaScript’s default behavior of moving declarations to the top of the current scope.
What is the difference between map()
, filter()
, and reduce()
?
map()
transforms elements, filter()
selects elements, and reduce()
combines elements into a single value.
What is a promise?
A promise is an object that represents the eventual completion or failure of an asynchronous operation.
What is destructuring?
Destructuring is a syntax that allows you to unpack values from arrays or properties from objects into distinct variables.
What is the difference between null
and undefined
?
undefined
means a variable has been declared but not assigned a value. null
is an assignment value that represents no value.
What is the difference between synchronous and asynchronous code?
Synchronous code runs sequentially, blocking further execution until the current task finishes. Asynchronous code runs in the background and doesn’t block execution.
What is prototypal inheritance?
It’s a feature in JavaScript where objects can inherit properties and methods from other objects via the prototype chain.
What is the use of async
and await
?
async
declares a function that returns a promise. await
pauses the execution of an async
function until the promise resolves.
What is event delegation?
Event delegation is a technique where a single event listener on a parent element handles events from its child elements using event bubbling.
What is the spread operator (...
)?
It allows an iterable (like an array or object) to be expanded in places where zero or more arguments or elements are expected.
What is an Immediately Invoked Function Expression (IIFE)?
An IIFE is a function that runs immediately after it’s defined, often used to avoid polluting the global scope.
What is debouncing in JavaScript?
Debouncing is a technique to limit how often a function is executed by waiting for a pause in events before running the function.
What is the purpose of bind()
, call()
, and apply()
?
bind()
returns a new function with a specified this
. call()
and apply()
invoke a function with a specified this
, with apply()
using an array of arguments.
What are JavaScript modules?
Modules are reusable pieces of code that can be exported from one file and imported into another using export
and import
.
What is the difference between deep copy and shallow copy?
A shallow copy copies only the first level of the object, while a deep copy recursively copies all nested levels.
What is the Temporal Dead Zone (TDZ)?
TDZ is the time between the declaration of a variable with let
or const
and its initialization, where accessing it causes a ReferenceError.
What is the difference between .forEach()
and .map()
?
forEach()
executes a function for each element but returns undefined, while map()
returns a new array with transformed elements.
What are generator functions?
Generator functions are defined with function*
and use yield
to pause and resume execution, allowing lazy evaluation.