What kind of exports are more conducive to effective tree shaking?

  • Default exports
  • Named exports
  • All exports are treated equally by tree shaking.
  • Both default and named exports
Tree shaking is more effective with named exports, as it can selectively include or exclude specific exports based on usage. Default exports can still be tree shaken, but named exports provide more granularity.

What is the result of using a Symbol as a key in a JSON object when using JSON.stringify?

  • It serializes the symbol key along with its associated value.
  • It ignores the symbol key and only serializes other enumerable properties.
  • It throws an error since symbols cannot be used as keys in JSON objects.
  • It converts the symbol key to a string and serializes it.
When using JSON.stringify, symbols are ignored, and only other enumerable properties are serialized. Symbols are not convertible to strings in this context.

Can dynamic imports be conditional? If so, what is a real-world use case?

  • Yes, based on browser features
  • No, always loaded unconditionally
  • Yes, based on time of day
  • No, only for large modules
Dynamic imports can be conditional, for example, based on browser features. This allows loading different code based on the capabilities of the user's browser, optimizing performance and providing a better user experience.

Which method is used to catch errors in a Promise?

  • catchError
  • errorHandler
  • catch
  • handleError
The correct method to catch errors in a Promise is the catch method. It is used to handle both synchronous and asynchronous errors that may occur during the execution of the Promise. By chaining the catch method to a Promise, you can specify a callback function to handle the errors and take appropriate actions.

To convert a Set into an array, use the spread operator like this: [..._________].

  • Set
  • Map
  • Iterable
  • Collection
To convert a Set into an array, use the spread operator like this: [...Set]. Sets in ES6 are iterable, and using the spread operator allows you to convert the Set into an array easily.

Using _________ functions helps in maintaining function purity by not altering the original data structure.

  • Map
  • Reduce
  • Pure
  • Impure
Using pure functions helps in maintaining function purity by not altering the original data structure. Pure functions always produce the same output for the same input and do not modify external state, contributing to the predictability and reliability of the code.

Can destructuring assignment be used with arrays, and if so, how does it differ from object destructuring?

  • Yes, and it works the same as with objects
  • No, destructuring can only be used with objects
  • Yes, but the syntax is different from object destructuring
  • Yes, and it uses square brackets for the pattern
Destructuring assignment can be used with arrays in JavaScript. However, the syntax differs from object destructuring. With arrays, square brackets are used to indicate the pattern, making it distinct from object destructuring that uses curly braces.

What is the difference in execution timing between callbacks and Promises?

  • Callbacks may lead to callback hell due to nested structures, affecting the execution sequence.
  • Promises execute asynchronously, allowing better control over the flow of the program.
  • Execution timing is the same for both callbacks and Promises.
  • Callbacks always execute before Promises.
Promises provide a more straightforward approach to asynchronous programming, allowing developers to handle execution timing more efficiently. Callbacks, especially when nested, can lead to callback hell, making it challenging to manage the sequence of operations. This understanding is crucial for developers aiming to enhance code readability and manage asynchronous tasks effectively using Promises.

If a class extends another class, the constructor of the child class must call _______ to access the parent's properties.

  • super()
  • parent()
  • this()
  • extend()
If a class extends another class, the constructor of the child class must call super() to access the parent's properties. The super() function is used to invoke the constructor of the parent class, ensuring that the parent's properties are initialized correctly.

Which ES6 feature can be particularly useful in writing more readable recursive functions?

  • Arrow functions
  • Destructuring assignment
  • Rest and spread operators
  • Default function parameters
Arrow functions have a concise syntax, making the code more readable. They are particularly useful in recursive functions where brevity and clarity are crucial.