In an AJAX call using Promises, _________ is a method used to parse the JSON response.

  • .parseJSON()
  • .toJSON()
  • .parse()
  • .json()
The correct method for parsing the JSON response in a Promises-based AJAX call is .json(). This method is specifically designed to extract and parse the JSON data from the response.

Question 2: In a large-scale application, how does the use of absolute imports in ES6 modules affect maintainability and refactoring compared to relative imports?

  • Easier refactoring, better maintainability
  • No significant impact
  • Harder refactoring, lower maintainability
  • Depends on the project structure
Using absolute imports can make refactoring more challenging, as changes to the file structure may require updating import paths throughout the codebase. This can result in lower maintainability compared to relative imports, which automatically adjust to the file's position. Consider the trade-offs based on project size and structure.

In what scenario would a WeakSet be more appropriate than a Set for managing DOM elements?

  • When managing temporary or transient DOM elements that should not prevent garbage collection.
  • WeakSet is preferred for static and permanent DOM elements to enhance performance.
  • In scenarios where strict ordering of DOM elements is crucial.
  • When managing a small number of DOM elements with known lifetimes.
WeakSet is suitable for scenarios where the collection of DOM elements may vary, and automatic garbage collection is desired.

How can you import an entire module as an object in ES6?

  • import * as myModule from './myModule';
  • import { myModule } from './myModule';
  • import myModule from './myModule';
  • import { * } from './myModule';
In ES6, you can use the import * as alias syntax to import the entire module as an object. This allows you to access all exported values through the alias object.

What happens when you try to create a new Symbol using the new keyword?

  • Error is thrown
  • A new Symbol is created
  • It returns an existing Symbol
  • Symbols cannot be created using new
When attempting to create a Symbol using the new keyword, it results in an error. Symbols are primitive values, and using the new keyword with them is not allowed. Symbols are typically created without the new keyword.

In a project using ES6 modules, if you need to dynamically load a module based on a user's action, which import method would you use?

  • import()
  • require()
  • import dynamic
  • import lazy
In ES6, the import() function allows dynamic loading of modules. It returns a promise that resolves to the module namespace object, allowing you to load modules conditionally or based on user actions.

If you are implementing a function that will be used as a callback, which might benefit from lexical scoping of this, what type of function would you choose?

  • Arrow function
  • Regular function
  • Class method
  • Anonymous function
Arrow functions are suitable for callbacks, as they capture the "this" value from their enclosing scope, providing a clean and concise way to maintain lexical scoping.

When destructuring an array, the syntax _________ is used to skip over elements.

  • ...
  • ++
  • //
  • --
Destructuring an array in ES6 allows for skipping elements using the spread/rest syntax .... This is particularly useful when certain elements are not needed in the assignment.

A class in ES6 is a special type of function, and it can be declared using the ________ keyword.

  • function
  • class
  • object
  • define
In ES6, the class keyword is used to declare a class. Unlike functions, classes support class-based inheritance, providing a cleaner syntax for object-oriented programming in JavaScript.

Which tool is essential for enabling tree shaking in a modern JavaScript project?

  • Webpack
  • Babel
  • ESLint
  • npm
Tree shaking is a process in Webpack that eliminates unused code, reducing the bundle size. By configuring Webpack properly, you can enable tree shaking and optimize your project for better performance.