Yes Flashcards

(67 cards)

1
Q

What is the difference between var, let, and const?

A

var is function-scoped and hoisted; let and const are block-scoped. const cannot be reassigned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a closure in JavaScript?

A

A closure is a function that remembers its outer scope even after the outer function has finished executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the difference between == and ===.

A

== checks for value equality with type coercion, while === checks for both value and type equality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the event loop?

A

It’s the mechanism that handles asynchronous operations by placing callbacks in the queue and executing them after the main call stack is clear.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are arrow functions and how do they differ from regular functions?

A

Arrow functions use a shorter syntax and do not have their own this context—they inherit it from the parent scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does this behave in JavaScript?

A

this refers to the object that is calling the function, and behaves differently in strict mode, arrow functions, and event handlers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is hoisting?

A

Hoisting is JavaScript’s default behavior of moving declarations to the top of the current scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between map(), filter(), and reduce()?

A

map() transforms elements, filter() selects elements, and reduce() combines elements into a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a promise?

A

A promise is an object that represents the eventual completion or failure of an asynchronous operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is destructuring?

A

Destructuring is a syntax that allows you to unpack values from arrays or properties from objects into distinct variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between null and undefined?

A

undefined means a variable has been declared but not assigned a value. null is an assignment value that represents no value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between synchronous and asynchronous code?

A

Synchronous code runs sequentially, blocking further execution until the current task finishes. Asynchronous code runs in the background and doesn’t block execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is prototypal inheritance?

A

It’s a feature in JavaScript where objects can inherit properties and methods from other objects via the prototype chain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the use of async and await?

A

async declares a function that returns a promise. await pauses the execution of an async function until the promise resolves.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is event delegation?

A

Event delegation is a technique where a single event listener on a parent element handles events from its child elements using event bubbling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the spread operator (...)?

A

It allows an iterable (like an array or object) to be expanded in places where zero or more arguments or elements are expected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is an Immediately Invoked Function Expression (IIFE)?

A

An IIFE is a function that runs immediately after it’s defined, often used to avoid polluting the global scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is debouncing in JavaScript?

A

Debouncing is a technique to limit how often a function is executed by waiting for a pause in events before running the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the purpose of bind(), call(), and apply()?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are JavaScript modules?

A

Modules are reusable pieces of code that can be exported from one file and imported into another using export and import.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the difference between deep copy and shallow copy?

A

A shallow copy copies only the first level of the object, while a deep copy recursively copies all nested levels.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the Temporal Dead Zone (TDZ)?

A

TDZ is the time between the declaration of a variable with let or const and its initialization, where accessing it causes a ReferenceError.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the difference between .forEach() and .map()?

A

forEach() executes a function for each element but returns undefined, while map() returns a new array with transformed elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are generator functions?

A

Generator functions are defined with function* and use yield to pause and resume execution, allowing lazy evaluation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is a symbol in JavaScript?
A symbol is a unique and immutable primitive value often used to create unique object keys.
26
What is optional chaining?
Optional chaining (`?.`) allows safe access to deeply nested object properties without throwing an error if a reference is null or undefined.
27
What is the difference between `Object.freeze()` and `Object.seal()`?
`Object.freeze()` makes an object immutable. `Object.seal()` prevents new properties but allows modification of existing ones.
28
How does event bubbling work in the DOM?
Event bubbling starts from the target element and propagates up to the root, triggering any parent event listeners.
29
What is a thunk in JavaScript?
A thunk is a function that delays a computation or calculation until its result is needed.
30
What is a memory leak in JavaScript?
A memory leak occurs when memory that is no longer needed is not released, often due to lingering references.
31
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.
32
What is a closure in JavaScript?
A closure is a function that remembers its outer scope even after the outer function has finished executing.
33
Explain the difference between `==` and `===`.
`==` checks for value equality with type coercion, while `===` checks for both value and type equality.
34
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.
35
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.
36
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.
37
What is hoisting?
Hoisting is JavaScript's default behavior of moving declarations to the top of the current scope.
38
What is the difference between `map()`, `filter()`, and `reduce()`?
`map()` transforms elements, `filter()` selects elements, and `reduce()` combines elements into a single value.
39
What is a promise?
A promise is an object that represents the eventual completion or failure of an asynchronous operation.
40
What is destructuring?
Destructuring is a syntax that allows you to unpack values from arrays or properties from objects into distinct variables.
41
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.
42
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.
43
What is prototypal inheritance?
It’s a feature in JavaScript where objects can inherit properties and methods from other objects via the prototype chain.
44
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.
45
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.
46
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.
47
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.
48
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.
49
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.
50
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`.
51
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.
52
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.
53
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.
54
What are generator functions?
Generator functions are defined with `function*` and use `yield` to pause and resume execution, allowing lazy evaluation.
55
What is a symbol in JavaScript?
A symbol is a unique and immutable primitive value often used to create unique object keys.
56
What is optional chaining?
Optional chaining (`?.`) allows safe access to deeply nested object properties without throwing an error if a reference is null or undefined.
57
What is the difference between `Object.freeze()` and `Object.seal()`?
`Object.freeze()` makes an object immutable. `Object.seal()` prevents new properties but allows modification of existing ones.
58
How does event bubbling work in the DOM?
Event bubbling starts from the target element and propagates up to the root, triggering any parent event listeners.
59
What is a thunk in JavaScript?
A thunk is a function that delays a computation or calculation until its result is needed.
60
What is a memory leak in JavaScript?
A memory leak occurs when memory that is no longer needed is not released, often due to lingering references.
61
What is type coercion in JavaScript?
Type coercion is the automatic or implicit conversion of values from one data type to another.
62
What is the result of `'5' + 1` in JavaScript?
'51' – because 1 is coerced into a string and concatenated.
63
What is the result of `'5' - 1` in JavaScript?
4 – because '5' is coerced into a number, and subtraction is performed.
64
What does `true + 1` evaluate to?
2 – because `true` is coerced to 1.
65
How do you explicitly convert a value to a number in JavaScript?
Use `Number(value)`.
66
Does `false == 0` return true or false?
True – because `false` is coerced into 0 during loose equality comparison.
67
What is the difference between `==` and `===` regarding type coercion?
`==` allows type coercion during comparison, while `===` requires both value and type to be the same.