In JavaScript, what happens when the call stack is full, commonly known as 'Stack Overflow'?

  • The program crashes, and an error is thrown
  • The excess functions are moved to the heap
  • The browser prompts the user with an error message
  • The call stack automatically expands
When the call stack is full, a 'Stack Overflow' occurs, leading to a runtime error. This happens when the stack size exceeds its limit, usually due to excessive function calls, resulting in a crash.

Can a child class in ES6 have a constructor without calling super()?

  • Yes
  • No
  • Depends on the parent class constructor
  • Only in certain scenarios
No, a child class in ES6 must call super() in its constructor to invoke the constructor of its parent class. This is essential for proper initialization and inheritance of properties from the parent class.

In functional programming, _________ is a technique used to avoid side effects by ensuring data is not modified.

  • Mutable State
  • Immutability
  • Asynchronous
  • Prototyping
In functional programming, immutability is a technique that involves not modifying the data once it is created. This helps avoid side effects and makes functions more predictable and easier to reason about. Immutability ensures that data remains constant throughout its lifecycle.

Can a generator function yield another generator function? If so, how is it achieved?

  • No, it is not possible
  • Yes, using yield* keyword
  • Yes, using async keyword
  • Yes, using yield keyword
Yes, a generator function can yield another generator function using the yield* keyword. This allows for the delegation of the generator control, enabling the composed use of generators within generators. This feature enhances the modularity and reusability of generator functions.

How does a pure function handle dependencies or external variables?

  • Manages dependencies internally
  • Avoids external dependencies
  • Handles dependencies through callbacks
  • Utilizes global variables
In a pure function, dependencies are avoided to maintain purity. External variables could introduce side effects, violating the principle of purity.

In a for...of loop, the _________ method of an iterable object is called to retrieve values.

  • next()
  • iterate()
  • forEach()
  • value()
In a for...of loop, the next() method of an iterable object is called to retrieve values. The next() method is automatically called in each iteration of the loop, returning an object with the value property containing the current value.

How does the lack of enumeration in WeakMap and WeakSet impact their use cases?

  • Lack of enumeration in WeakMap and WeakSet prevents direct access to their elements.
  • Enumeration is not essential in WeakMap and WeakSet, as they are designed for scenarios where enumeration is not needed.
  • Lack of enumeration provides an added layer of security, making it difficult for external code to access the internal state of these structures.
  • Enumeration is not relevant in the context of WeakMap and WeakSet, as their primary use is for memory management.
Lack of enumeration allows these structures to be more suitable for scenarios where privacy and encapsulation are critical.

When optimizing a web application for performance, considering the need for tree shaking and module caching, which module system offers more advantages?

  • ES6 Modules
  • CommonJS
  • Both have similar performance optimizations
  • Depends on the specific use case
ES6 Modules provide better support for tree shaking, a process that eliminates unused code during the build, resulting in smaller bundles and improved performance. Additionally, ES6 Modules support native module caching, further enhancing performance by reducing redundant module loading.

In a situation where a web application needs to fetch data from an API and handle both the data response and possible errors, what are the best practices using Promises?

  • Using async/await
  • Promise.catch
  • Using try/catch
  • Using setTimeout
The best practice in handling both successful data responses and errors with Promises is by using async/await. This allows for cleaner and more readable code, making it easier to handle both resolved and rejected promises in a structured and organized manner.

How does the Promise.all method interact with async/await?

  • Waits for all promises to resolve and then proceeds
  • Rejects if any of the promises reject
  • Executes promises concurrently
  • Resolves immediately without waiting
Promise.all waits for all promises to resolve successfully before proceeding. If any of the promises reject, the entire Promise.all rejects. This makes it useful when you have multiple asynchronous operations that can be executed concurrently and you want to wait for all of them to complete. When combined with async/await, you can use it to await multiple asynchronous operations concurrently.