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 a pure function handle dependencies or external variables?

  • Manages dependencies internally
  • Avoids external dependencies
  • Handles dependencies through callbacks
  • Utilizes global variables
In a pure function, dependencies are avoided to maintain purity. External variables could introduce side effects, violating the principle of purity.

In a for...of loop, the _________ method of an iterable object is called to retrieve values.

  • next()
  • iterate()
  • forEach()
  • value()
In a for...of loop, the next() method of an iterable object is called to retrieve values. The next() method is automatically called in each iteration of the loop, returning an object with the value property containing the current value.