How do you remove an item from a Map in ES6?

  • delete method
  • remove method
  • pop method
  • discard method
In ES6, you can use the delete method to remove an item from a Map. This method takes the key as an argument and removes the corresponding key-value pair from the Map.

Describe a scenario where dynamic imports would be beneficial in a server-side JavaScript environment.

  • In an environment where all server-side code is loaded upfront.
  • When server-side modules need to be loaded on-demand based on specific requests.
  • Only in scenarios where server-side code is minimal.
  • Use static imports to include all server-side modules during startup.
Dynamic imports in a server-side JavaScript environment are beneficial when specific modules are required on-demand, such as handling different types of requests. This helps optimize resource usage and improve response times in scenarios with varying workloads.

If a variable declared with const is an object or array, its properties can still be ________.

  • Modified
  • Deleted
  • Reassigned
  • Hidden
In JavaScript, when a variable is declared with const, it means the reference to the object or array is constant, not the actual content. Therefore, you can't reassign the variable, but you can still modify, delete, or add properties to the object or array.

In what ways can destructuring assignment be utilized in function parameters?

  • Extract specific values
  • Set default parameter values
  • Both 1 and 2
  • Neither 1 nor 2
Destructuring assignment in function parameters allows you to extract specific values from objects or arrays passed as arguments. Additionally, you can set default parameter values using destructuring, providing flexibility in handling different cases.

To create a pipeline of operations, functions can be composed using higher-order functions, known as __________.

  • Callbacks
  • Promises
  • Closures
  • Combinators
In functional programming, functions like compose or pipe are used as combinators to create a pipeline of operations by composing other functions. These are higher-order functions that take functions as arguments and return a new function that represents the composition of those functions.

When the call stack is busy, new requests get queued in the __________ for their turn to be processed.

  • Callback Queue
  • Microtask Queue
  • Event Loop
  • Task Queue
The correct option is Task Queue. When the call stack is occupied, new tasks are placed in the task queue to await their turn. The Event Loop manages the process of moving tasks from the task queue to the call stack. Understanding this mechanism is crucial for handling asynchronous operations effectively.

The __________ is responsible for executing the code, collecting and processing events, and executing queued sub-tasks.

  • Callback Queue
  • Event Loop
  • Promise
  • Closure
The Event Loop is a crucial part of JavaScript's concurrency model. It continuously checks the Call Stack and Callback Queue, ensuring the non-blocking execution of code.

In a project where a class needs to incorporate event-handling, logging, and validation behaviors, how would mixins and composition be used?

  • By using inheritance and overriding methods in the class.
  • By applying mixins through multiple inheritance.
  • By using composition and creating separate classes for each behavior, then combining them.
  • By using mixins and composing them into the class.
Mixins in ES6 can be applied by creating separate modules for each behavior (event-handling, logging, validation) and then composing these mixins into the class. This promotes code reusability and maintainability.

In an async function, what happens to unhandled exceptions?

  • They are automatically caught by the global error handler
  • They cause the program to crash immediately
  • They propagate to the nearest catch block
  • They result in an unhandled promise rejection
Unhandled exceptions in an async function result in unhandled promise rejections. This can lead to unexpected behavior or crashes if not properly addressed. It's crucial to handle errors appropriately in async functions to ensure robust and error-resistant code.

What is the initial state of a JavaScript Promise when it is created?

  • Pending
  • Resolved
  • Rejected
  • Settled
When a Promise is created, it starts in the "Pending" state. This means that the Promise is neither fulfilled nor rejected. It's essentially in a pending state until the asynchronous operation it represents is completed.

What is the significance of weak references in WeakMap and WeakSet with regards to memory management?

  • Weak references in WeakMap and WeakSet allow for automatic garbage collection, preventing memory leaks.
  • Weak references are irrelevant in the context of WeakMap and WeakSet, as they don't impact memory management.
  • Weak references provide a way to create circular references, enhancing memory efficiency.
  • Weak references ensure that the referenced objects are not eligible for garbage collection, preserving memory.
Weak references in WeakMap and WeakSet enable automatic memory management by allowing the garbage collector to reclaim objects that are no longer reachable.

What is the primary advantage of using dynamic imports in JavaScript?

  • Code Splitting
  • Improved Code Readability
  • Faster Execution
  • Enhanced Browser Compatibility
Dynamic Imports in JavaScript allow for efficient code splitting. By loading only the modules that are needed at runtime, it improves the performance of the application, especially in large projects where not all code is required on every page.