How does a tagged template literal differ from a regular template literal?

  • A tagged template literal is enclosed in backticks and allows expressions to be embedded.
  • A regular template literal is enclosed in single quotes and cannot contain expressions.
  • A tagged template literal can be used for multiline strings.
  • A regular template literal cannot be assigned to a variable.
In a tagged template literal, a function (the tag function) is invoked, receiving the template string and evaluated expressions as arguments. This allows for custom string processing. Regular template literals do not involve a tag function.

What is the main difference between default and named exports in ES6 modules?

  • Default exports allow exporting a single value or function per module, while named exports allow exporting multiple values with distinct names.
  • Default exports can only be used with functions, whereas named exports can be used with any type of value.
  • Default exports are used for private components, while named exports are used for public components.
  • Default exports require an additional keyword for import, unlike named exports.
In ES6 modules, default exports are used to export a single value or function, while named exports allow exporting multiple values with distinct names. Default exports are particularly useful when there is only one main entity to be exported from a module.

Custom iterators can be created in JavaScript by defining a class with a Symbol.iterator method that returns an object implementing the _______ method.

  • iterate()
  • execute()
  • iterator()
  • next()
In JavaScript, custom iterators are created by defining a class with a Symbol.iterator method, and the method that needs to be implemented is 'next.' The Symbol.iterator method should return an object with a 'next' method.

The ________ field in package.json can be used to specify different entry points for importing a package in ES6.

  • "main"
  • "module"
  • "entry"
  • "import"
In ES6, the "module" field in package.json is used to specify the entry point for importing a package. It is the path to the main module of the package when imported.

Currying transforms a function with multiple arguments into a sequence of functions each taking a single ________.

  • Argument, Value, Parameter, Variable
  • Value, Parameter, Argument, Input
  • Parameter, Input, Variable, Argument
  • Input, Value, Argument, Parameter
Currying involves breaking down a function with multiple arguments into a series of functions, each taking a single parameter. This can enhance the flexibility and composability of functions.

When designing a class for a UI component, how would you define a method that shouldn't be accessible outside of the class?

  • Private Methods
  • Protected Methods
  • Public Methods
  • Static Methods
In ES6, to create a method that is not accessible outside of the class, you can use the # symbol before the method name, making it a private method. Private methods are encapsulated within the class, ensuring they are not accessible externally. This helps in controlling access to specific functionalities and maintaining the integrity of the class.

When designing a function to log user activity, what considerations should be made to maintain purity and manage side effects?

  • Store logs in a global array
  • Use asynchronous logging for better performance
  • Log only user actions without any additional data
  • Separate the logging logic from the main function
To maintain purity and manage side effects, the logging logic should be separated from the main function. This separation helps in isolating the side effect (logging) and makes the main function pure. Storing logs in a global array or mixing logging with the main function can lead to impurity.

In the context of recursion, how can destructuring assignments in ES6 improve code clarity?

  • Destructuring assignments have no impact on code clarity in recursive contexts.
  • They can introduce confusion in recursive code.
  • Destructuring assignments can simplify accessing nested values.
  • They only work with arrays and not objects in recursive scenarios.
Destructuring assignments in ES6 can enhance code clarity by simplifying the extraction of values from complex data structures. When dealing with recursive data, they make it easier to access nested values, leading to cleaner and more readable code.

What is a static method in an ES6 class?

  • A method that can only be called on instances of the class
  • A method that belongs to the class rather than an instance
  • A method that is defined using the static keyword
  • A method that cannot be accessed outside the class
In ES6, a static method is a method that belongs to the class itself rather than an instance. It is defined using the static keyword and can be called on the class itself, not on instances. This allows you to perform operations that are not specific to any instance but are related to the class as a whole.

In which environment (Node.js or browser) were ES6 Modules not originally supported?

  • Node.js
  • Browser
  • Both supported ES6 Modules
  • Neither supported ES6 Modules
ES6 Modules were not originally supported in Node.js but were supported in browsers. Node.js added support later.