What is the syntax to export a single function from an ES6 module?

  • export function myFunction() {}
  • export myFunction from 'module';
  • export { myFunction };
  • export default myFunction;
In ES6, to export a single function, you use the syntax export { myFunction };. This allows you to import it individually in another module. The export default is used for the default export, not a named one.

When using relative paths in ES6 module imports, what does './' and '../' signify?

  • Current directory
  • Parent directory
  • Root directory
  • Child directory
In ES6 module imports, './' represents the current directory, and '../' represents the parent directory. Understanding these path notations is crucial for correctly referencing modules within the project structure.

Can a module have both named and default exports?

  • Yes, a module can have both named and default exports simultaneously.
  • No, a module must choose either named or default exports.
  • Modules can have multiple default exports, but only one named export.
  • Named exports can only be used if there are no default exports in the module.
In ES6 modules, it's possible for a module to have both named and default exports. This flexibility allows developers to export a single main entity using default export and also export additional values using named exports.

The "sideEffects" property in package.json helps tree shaking by indicating if a module may contain _______.

  • Side Effects
  • Pure Functions
  • Impure Functions
  • Async Functions
The correct option is (b) Pure Functions. The "sideEffects" property, when set to false, informs the module bundler that the module does not have side effects, making it eligible for tree shaking. Pure functions are side effect-free functions that only depend on their input parameters, making them suitable for elimination during tree shaking.

What happens if you try to redeclare a variable declared with let in the same scope?

  • It generates an error
  • It assigns a new value to the variable
  • It creates a new variable with the same name
  • It deletes the variable
When you attempt to redeclare a variable with let in the same scope, it will generate an error. This is because variables declared with let cannot be redeclared in the same scope.

In what way does the super keyword facilitate inheritance in ES6 classes?

  • It allows access to the parent class's methods and properties
  • It creates an instance of the parent class
  • It prevents the child class from inheriting certain methods
  • It is used to instantiate the parent class
The super keyword in ES6 classes is used to access the methods and properties of the parent class. It is commonly used in the constructor of the child class to call the constructor of the parent class and initialize the inherited properties.

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.

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.