Which of the following best describes the purpose of functional composition?

  • Combining small, simple functions to build more complex ones
  • Declaring variables globally for easy access
  • Utilizing conditional statements for decision-making
  • Executing functions in parallel for efficiency
The purpose of functional composition is to combine small, simple functions to build more complex and reusable functions. By composing functions together, developers can create a flow of data transformation, leading to cleaner and more maintainable code. This approach aligns with the principles of functional programming, emphasizing immutability and pure functions. A strong grasp of functional composition is essential for developers aiming to write expressive and efficient JavaScript code.

How does caching of modules work differently in ES6 Modules compared to CommonJS?

  • ES6 Modules use a global cache for all modules
  • ES6 Modules have no caching mechanism
  • Each ES6 Module has its own cache
  • CommonJS has no module caching
In ES6 Modules, each module maintains its own cache, preventing duplication of work and ensuring consistency across the application. CommonJS, on the other hand, uses a global cache for all modules.

To define a function as a method in an object literal, ES6 syntax does not require the ________ keyword.

  • function
  • method
  • this
  • function
In ES6, when defining a method in an object literal, you can use the concise method syntax by omitting the "function" keyword, making the code more succinct and aligned with modern practices.

How does tree shaking differ between named and default exports?

  • Tree shaking is more effective with default exports
  • Tree shaking is more effective with named exports
  • Tree shaking treats both equally
  • Tree shaking cannot be used with ES6 modules
Tree shaking is more effective with default exports because the bundler can directly eliminate the unused default export, whereas with named exports, the bundler may include unnecessary exports even if only one is used.

Can you use destructuring assignment to assign default values to variables?

  • Yes
  • No
  • Only for primitive data types
  • Only for arrays
Yes, destructuring assignment in ES6 allows you to assign default values to variables. If the assigned value is undefined, the variable takes the default value specified. This feature enhances flexibility in handling variable assignments.

In a for...of loop, using let allows each iteration to have its own _________ scope.

  • Global
  • Block
  • Local
  • Function
The let keyword creates a block-scoped variable, so each iteration in a for...of loop has its own block scope. This helps prevent unintended variable hoisting and makes the code more predictable.

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

  • Default exports are used for exporting a single value or function, while named exports are used for exporting multiple values or functions from a module.
  • Default exports use the export default syntax, while named exports use the export { myFunction }; syntax.
  • Default exports are mandatory, while named exports are optional.
  • Default exports can be renamed during import using the as keyword, while named exports cannot be renamed.
The main difference is that default exports are for a single value or function, and named exports are for multiple values or functions. Default exports use export default while named exports use export { myFunction };.

ES6 arrow functions can make recursive functions more concise and _________.

  • Readable
  • Performant
  • Maintainable
  • Shorter
ES6 arrow functions, with their concise syntax, can make recursive functions shorter and more readable by eliminating the need for the 'function' keyword and providing implicit returns.

How does ES6 handle importing a module that is located in a node_modules folder?

  • Looks for the module in the current directory first, then checks the node_modules folder
  • Directly looks in the node_modules folder
  • Prioritizes searching in the node_modules folder before checking the current directory
  • Searches both the current directory and the node_modules folder simultaneously
In ES6, when importing a module, the resolution algorithm prioritizes searching the node_modules folder before checking the current directory. This allows for better organization of dependencies and avoids naming conflicts with local modules. It simplifies the module import process and enhances code maintainability by following a standardized approach to handle third-party libraries.

What happens when you try to import a non-existent named export from a module?

  • It will result in an error at runtime.
  • It will import the default export instead.
  • It will create an empty object for the named export.
  • It will import all exports from the module.
If you try to import a non-existent named export, it will result in an error at runtime. It's important to ensure that the named exports you are trying to import actually exist in the module.

How does the yield* keyword differ from yield in a generator function?

  • Both are equivalent
  • yield* is used for delegating to another generator or iterable
  • yield is used for async operations
  • yield* is used for synchronous operations
The yield* keyword in a generator function is used for delegating to another generator or iterable. It allows you to compose generators and is often used for iterating over iterable objects within the generator function. On the other hand, yield is used to pause the generator and yield a value to the caller.

In what scenarios is it more beneficial to use tagged template literals over regular template literals?

  • When dynamic string processing or transformation of the template is required.
  • When simple string concatenation suffices for the task.
  • Tagged template literals are only used in specific edge cases.
  • When you need to create a static string with fixed content.
Tagged template literals provide a powerful mechanism for customizing string output, making them beneficial in scenarios where dynamic content manipulation is necessary, such as in i18n (internationalization) or code generation. Regular template literals are simpler and more suitable for static strings.