JavaScript Internals & Advanced Concepts Flashcards
(52 cards)
What is an execution context in JavaScript?
It’s an abstract concept describing the environment where code is evaluated and executed, including scope, variables, and the value of ‘this’.
What is the call stack?
The call stack is a data structure that tracks function invocation, executing the most recent function call first (LIFO).
What is a closure in JavaScript?
A closure is a function that retains access to its lexical scope even after the outer function has finished executing.
What is memory management in JavaScript?
It involves allocating and releasing memory for variables, objects, and functions used in the program.
What is garbage collection in JavaScript?
It is the process of automatically reclaiming memory occupied by objects no longer reachable in the code.
What is the difference between deep and shallow copy?
A shallow copy copies only top-level properties, while a deep copy recursively copies all nested properties.
What is currying in JavaScript?
Currying is the process of breaking a function with multiple arguments into a series of functions that each take one argument.
What is debouncing in JavaScript?
Debouncing delays a function’s execution until a certain time has passed since the last call.
What is throttling in JavaScript?
Throttling limits a function to execute at most once in a specified period.
What is an advantage of the call stack model?
It simplifies function invocation tracking and local execution context.
What is a disadvantage of the call stack model?
Too many recursive calls can lead to stack overflow errors.
What is an advantage of closures?
They enable private variables and maintain state across function calls.
What is a disadvantage of closures?
They can cause memory leaks if references to outer scopes are not properly cleaned up.
What is an advantage of automatic garbage collection?
It simplifies memory management for developers.
What is a disadvantage of automatic garbage collection?
It can lead to non-deterministic memory cleanup, causing performance hiccups.
What is a best practice with closures?
Avoid overusing closures in long-lived contexts to prevent memory leaks.
What is a best practice with memory management?
Avoid global variables and detach event listeners when no longer needed.
What is a best practice with deep vs shallow copies?
Use deep copies when working with nested objects that need to be independently modified.
What is a best practice with debouncing and throttling?
Use debouncing for user input, and throttling for scroll or resize events.
What is a use case for execution context and call stack?
Debugging function call chains and understanding async stack traces.
What is a use case for closures?
Implementing data encapsulation and factory functions.
What is a use case for garbage collection?
Freeing memory in long-running servers or applications to maintain performance.
What is a use case for deep copy?
Cloning application state in Redux or similar state management libraries.
What is a use case for currying?
Creating reusable, configurable functions in functional programming.