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.

In a scenario involving an e-commerce site, how can currying be used to handle different types of discounts for products?

  • Simplifying Discount Logic and Promoting Reusability
  • Increasing Code Complexity and Redundancy
  • Centralizing Discount Calculation in a Single Function
  • Improving Security and Authorization for Discounts
Currying enables breaking down the discount calculation into partial functions, making the logic more modular. Each partial function can handle a specific type of discount. This approach simplifies the discount management system, promotes code reusability, and allows for easier maintenance. Centralizing discount logic with currying enhances the overall flexibility and maintainability of the e-commerce application.

What is the difference between defining methods in ES5 and ES6 object literals?

  • Function Declaration
  • Shorthand Syntax
  • Prototype Extension
  • Arrow Functions
In ES6 object literals, the method definition can be written using shorthand syntax, avoiding the need for the function keyword. This not only makes the code more concise but also automatically assigns a non-enumerable property to the method, leading to improved performance.

Can a class in ES6 contain constructor functions?

  • Yes
  • No
  • Only if explicitly declared
  • Only if it extends another class
Yes, a class in ES6 can contain a constructor function. The constructor is a special method that gets called when an object is instantiated from the class. It is commonly used for initializing object properties.

When used in a function argument, what does the rest operator do with the supplied arguments?

  • Gathers them into an array
  • Ignores them
  • Converts them to a string
  • Spreads them to all variables
The rest operator (...) in a function parameter allows you to gather all the remaining arguments into a single array. This is helpful when you have a variable number of arguments and want to process them as an array within the function.

In ES6, how can the spread operator (...) be used in a recursive function?

  • Using the spread operator in a recursive function allows for the expansion of an array or iterable, enabling the passing of individual elements as arguments. This can be useful when dealing with variable argument lists in recursive calls.
  • The spread operator can be employed to concatenate arrays, ensuring a more efficient handling of recursive calls where arrays need to be merged or combined.
  • It is possible to use the spread operator to clone objects within a recursive function, providing a mechanism to duplicate complex data structures without modifying the original objects.
  • Utilizing the spread operator in a recursive function helps to flatten nested arrays, simplifying the processing of deeply nested structures in the recursive calls.
The correct usage of the spread operator in a recursive function involves spreading the array or iterable inside the function's argument list. This is particularly helpful when dealing with functions that accept a variable number of arguments, allowing for flexibility in recursive calls.

If a variable declared with const is an object or array, its properties can still be ________.

  • Modified
  • Deleted
  • Reassigned
  • Hidden
In JavaScript, when a variable is declared with const, it means the reference to the object or array is constant, not the actual content. Therefore, you can't reassign the variable, but you can still modify, delete, or add properties to the object or array.

Describe a scenario where dynamic imports would be beneficial in a server-side JavaScript environment.

  • In an environment where all server-side code is loaded upfront.
  • When server-side modules need to be loaded on-demand based on specific requests.
  • Only in scenarios where server-side code is minimal.
  • Use static imports to include all server-side modules during startup.
Dynamic imports in a server-side JavaScript environment are beneficial when specific modules are required on-demand, such as handling different types of requests. This helps optimize resource usage and improve response times in scenarios with varying workloads.

How do you remove an item from a Map in ES6?

  • delete method
  • remove method
  • pop method
  • discard method
In ES6, you can use the delete method to remove an item from a Map. This method takes the key as an argument and removes the corresponding key-value pair from the Map.