What is the default behavior of module resolution in ES6 when importing a module without specifying a file extension?

  • Resolves to the module with the specified name
  • Resolves to the module with the specified name, followed by ".js"
  • Resolves to the module with the specified name, followed by ".mjs"
  • Resolves to the module with the specified name, followed by ".json"
In ES6, when a module is imported without a file extension, the module resolution algorithm looks for the module with the specified name followed by ".js". If not found, it looks for the module with ".mjs" and then ".json". This flexibility allows developers to omit file extensions, and the resolution algorithm handles it accordingly.

An async function always returns a __________.

  • Promise
  • Callback
  • Synchronous Value
  • Undefined
In an asynchronous function, the return value is always a Promise. This allows for better handling and chaining of asynchronous operations.

Question 3: When setting up a mono-repo with multiple packages, how does ES6 module resolution impact the sharing of code across different packages?

  • Facilitates code sharing through relative imports
  • Hinders code sharing across packages
  • Enables code sharing through global imports
  • Requires a centralized package for sharing
In a mono-repo with multiple packages, using relative imports in ES6 modules can facilitate code sharing. It allows packages to import modules from one another directly, enhancing modularity and reusability. This approach avoids a centralized package and promotes a more decentralized and modular code organization.

How does the ES6 specification handle tail call optimization and what are its limitations in JavaScript implementations?

  • ES6 specification doesn't explicitly mandate tail call optimization.
  • It mandates tail call optimization, but its implementation varies.
  • Tail call optimization is not supported in ES6.
  • It is only applicable to specific cases in ES6.
In ES6, tail call optimization is mandated, but its implementation may vary across JavaScript engines. The limitation lies in inconsistent support across different environments, making it crucial to check engine compatibility when relying on this optimization.

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.