Consider a scenario where you have an array of numbers, and you need to create a new array with only the numbers greater than 10. Which method would you use?

  • filter
  • map
  • reduce
  • forEach
In this scenario, the most suitable array method is filter. The filter method is designed for creating a new array containing elements that pass a certain condition. It allows you to filter out numbers greater than 10 effectively.

If you have a Symbol mySymbol, you can access its description using mySymbol.__________.

  • name
  • description
  • valueOf
  • toString
The correct property to access the description of a Symbol is description. The description property is used to get or set the description of a Symbol, providing additional information about the Symbol.

When a generator function is initially called, it returns a(n) __________ object.

  • Generator
  • Promise
  • Iterator
  • Iterable
When a generator function is called, it returns an iterator object. This object can be used to iterate through the values generated by the generator using the next() method. The other options do not represent the initial return type of a generator function.

How does ES6 support dynamic property names in object literals?

  • Computed Property Names
  • Object Linking
  • Dynamic Key Binding
  • Property Aliasing
ES6 supports dynamic property names through computed property names. By using square brackets around an expression within an object literal, you can create properties with names determined at runtime. This enhances the flexibility and expressiveness of object literals.

Tree shaking is most effective when modules use _______ exports rather than wildcard exports.

  • Named
  • Default
  • All
  • Individual
Tree shaking is a technique in JavaScript used to eliminate unused code during the build process. When modules use named exports, it allows the bundler to selectively include only the functions or variables that are actually used, making tree shaking more effective. Default exports and wildcard exports can complicate this process, leading to less efficient tree shaking.

If an arrow function is written with a single expression, the return value is the result of the expression without using the ________ keyword.

  • Break
  • Return
  • Yield
  • Exit
In arrow functions, if the function body consists of a single expression, you can omit the curly braces {} and the return keyword. The return value will be the result of the expression automatically.

To access a parent class's method in a child class, the __________ keyword is used inside the method.

  • super
  • this
  • parent
  • extends
In JavaScript, the super keyword is used to refer to the parent class. When used inside a method in a child class, it allows you to call the corresponding method in the parent class. This is particularly useful for accessing and invoking the parent class's method from within the child class.

In terms of scope, how do variables and functions behave differently in ES6 Modules compared to CommonJS modules?

  • Variables and functions have block scope
  • Variables have block scope, functions have global scope
  • Variables and functions have global scope
  • Variables have global scope, functions have block scope
ES6 Modules introduce block scope for both variables and functions, offering better encapsulation. In contrast, CommonJS has function-level scope for variables and global scope for functions, leading to potential issues with variable leakage.

If a module exports several named items, how can you import all of them at once?

  • import * as allExports from 'module';
  • import { export1, export2 } from 'module';
  • import allExports from 'module';
  • import { * } from 'module';
To import all named exports from a module at once, you use the syntax import * as allExports from 'module';. This creates an object containing all the exports, and you can access them using dot notation, e.g., allExports.exportName.

What is a key difference between a Map and a WeakMap in JavaScript?

  • Both can store key-value pairs, but the keys in WeakMap must be objects, and they don't prevent the objects from being garbage collected.
  • Maps allow any data type as keys, while WeakMaps only allow objects as keys.
  • Maps are iterable, while WeakMaps are not iterable.
  • WeakMaps have a getKeys method to retrieve all keys.
Maps are versatile and allow various data types as keys, while WeakMaps are designed for enhanced privacy, with keys limited to objects and no direct method for key retrieval.