Q3: If you encounter a performance issue in a web application due to extensive use of prototypes, what would be your approach to optimize it?

  • Utilize static methods
  • Minimize prototype chain depth
  • Convert prototypes to classes
  • Use Object.setPrototypeOf()
To optimize performance, reducing the depth of the prototype chain is crucial. This minimizes the number of lookups required during property access, enhancing overall efficiency. It's essential to carefully design the prototype hierarchy for better performance in large-scale applications.

What is the outcome when attempting to instantiate a class without the 'new' keyword in ES6?

  • It results in a runtime error
  • It creates a new instance but without the class's constructor being called
  • It has no impact; both 'new' and non-'new' instantiation work the same way
  • It leads to a memory leak
If a class is instantiated without the 'new' keyword, it throws a runtime error. The 'new' keyword is crucial for invoking the constructor and properly creating an instance of the class.

When using const to declare a variable, what type of assignment is mandatory?

  • Reassignment
  • Initialization
  • Increment
  • Declaration
When you declare a variable with const, you must initialize it with a value. const variables cannot be declared without an initial value, and they cannot be reassigned to a different value after initialization.

Consider a function that fetches user data from an API. How can this function be refactored to adhere to the principles of pure functions?

  • Return the fetched data directly
  • Introduce a callback for data processing
  • Include a random delay in fetching data
  • Use global variables for storing the fetched data
To make the function pure, it should return the fetched data directly without relying on external state or global variables. Introducing a callback or using global variables can introduce side effects, which contradicts the principles of pure functions.

Can the spread operator be used to combine two arrays into one in ES6?

  • Yes
  • No
  • Only if the arrays are of the same length
  • Only if the arrays are of different types
Yes, the spread operator can be used to combine two arrays into one by spreading the elements of both arrays into a new array. It's a concise way of merging arrays without modifying the original arrays.

In a Promise-based AJAX call, ________ is used to asynchronously await the response without blocking the execution.

  • await
  • then
  • catch
  • async
In a Promise-based AJAX call, the await keyword is used to asynchronously await the response without blocking the execution. This allows the code to continue its execution while waiting for the AJAX response.

Q2: Given a scenario where a subclass needs to modify a method inherited from a parent class, how would you implement this in ES6?

  • Use the 'extends' keyword
  • Utilize the 'super' keyword
  • Override the method in the subclass
  • Employ the 'Object.create()' method
In ES6, you can implement method overriding by defining the method with the same name in the subclass. This allows the subclass to provide a specialized implementation while still inheriting from the parent class.

How do you import a default export from a module?

  • Use the import keyword followed by any name of your choice, as the default export has no specific name.
  • Use the import default statement followed by the name specified in the exporting module.
  • Use the import { default } from 'module'; syntax.
  • Use the import * as alias from 'module'; syntax.
To import a default export from an ES6 module, you use the import keyword followed by any name of your choice, as the default export does not have a specific name. The imported name serves as an alias for the default export in your code.

Higher-order functions that alter the execution context of another function are often referred to as __________.

  • Decorators
  • Generators
  • Closures
  • Combinators
Decorators in JavaScript are higher-order functions that alter the behavior or execution context of another function. They are often used to add functionalities to functions or methods.

When exporting a class or function as a default export, it's not necessary to use the ________ keyword.

  • export default
  • default
  • export
  • class
When exporting a class or function as a default export, you can simply use export default followed by the class or function declaration without explicitly using the function or class keywords.