What happens when undefined is passed to a function with a default parameter?

  • The default parameter is used
  • An error is thrown
  • The function assigns a default value
  • It takes the value 'undefined'
When 'undefined' is passed, the default parameter is used. Explanation should cover how default parameters handle 'undefined' and when they come into play.

To optimize tree shaking, developers should avoid _______ side effects in their module code.

  • Pure
  • Impure
  • Global
  • Conditional
Tree shaking relies on the ability to analyze and remove dead code. Side effects in module code, especially impure ones, can hinder the accuracy of tree shaking. Developers are encouraged to write "pure" functions and modules, which have no side effects and make tree shaking more effective.

Can getter and setter functions be defined within ES6 object literals?

  • Yes, both getter and setter functions can be defined.
  • No, only getter functions are allowed.
  • No, only setter functions are allowed.
  • No, neither getter nor setter functions are allowed.
In ES6 object literals, both getter and setter functions can be defined using the concise method syntax. This feature allows developers to encapsulate access to object properties, providing a cleaner and more controlled way to retrieve and set values. Using getter and setter functions within object literals enhances the encapsulation of data and promotes a more modular code structure.

What is the primary use case for static properties in ES6 classes?

  • Improve code organization
  • Enable access to class-specific information
  • Facilitate class inheritance
  • Enhance instance-specific functionality
Static properties in ES6 classes are used primarily to facilitate class inheritance. They allow sharing of properties among all instances of a class and provide a common base for subclasses. This improves code organization and promotes the reusability of code in an object-oriented manner.

Can a higher-order function return another function as its output?

  • Yes
  • No
  • Maybe
  • It depends
A higher-order function can indeed return another function as its output. This feature is powerful for creating functions that can be composed and reused in different contexts.

What is the purpose of the WeakMap and WeakSet in ES6 compared to Map and Set?

  • They have better performance characteristics for certain use cases.
  • They are used for storing weakly held references to objects.
  • They have additional methods for manipulating keys and values.
  • They have stricter key equality rules.
WeakMap and WeakSet are designed for scenarios where you want to associate additional data with objects without preventing garbage collection. They are used for weakly held references.

What are the limitations of destructuring assignment when dealing with complex data structures?

  • Limited support for nested structures
  • Inability to rename variables
  • Difficulty in handling arrays
  • All of the above
Destructuring assignment may face limitations with complex nested structures, making it challenging to destructure deeply nested objects or arrays. Additionally, it lacks the ability to rename variables, and handling arrays can be trickier in certain scenarios.

Arrow functions do not have their own this keyword; instead, they ________ the this value from the enclosing execution context.

  • Absorb
  • Inherit
  • Borrow
  • Capture
Arrow functions in JavaScript do not have their own this context. Instead, they inherit the this value from the enclosing execution context. This behavior is different from regular functions, which have their own this binding.

In a scenario where you need to create multiple objects with similar properties and methods, how would you utilize ES6 classes to achieve this?

  • Prototypal Inheritance
  • Object Factories
  • Constructor Functions
  • ES6 Classes
In ES6, classes provide a cleaner syntax for creating objects with shared properties and methods. Options A, B, and C are also ways to achieve object creation, but ES6 classes offer a more concise and structured approach.

How can enhanced object literals in ES6 improve the process of creating objects that inherit from another object?

  • Facilitates concise syntax for defining the prototype chain
  • Enables automatic inheritance through the extends keyword
  • Introduces mixins for flexible composition of properties
  • Provides a dedicated Object.extend method for inheritance
Enhanced object literals in ES6 simplify the process of creating objects that inherit from another object by providing a concise syntax for defining the prototype chain. This concise syntax enhances code readability and reduces the boilerplate code associated with prototype-based inheritance, making it more accessible and efficient.

The __________ file in a module directory helps in defining the entry point for the module in ES6.

  • main.js
  • module.js
  • index.js
  • entry.js
In ES6, the index.js file serves as the default entry point for a module within a directory. It is automatically recognized when importing the module.

Can you use the arguments object inside an arrow function?

  • Yes, arrow functions have access to the arguments object
  • No, arrow functions do not have access to the arguments object
  • Only if the arrow function is declared with the 'arguments' keyword
  • Yes, but only in strict mode
Arrow functions do not have their own 'arguments' object. They inherit it from the enclosing scope, which may lead to unexpected behavior. Option B is correct.