Which method is used to send an AJAX request when using the Fetch API with Promises?
- fetch()
- send()
- request()
- ajax()
The fetch() method is used to send an AJAX request when utilizing the Fetch API with Promises. It is a modern and flexible API for making HTTP requests and handling responses.
The _________ method executes a provided function once for each array element.
- forEach
- map
- filter
- reduce
The correct answer is forEach. This method iterates over each element in an array and executes a provided function once for each element. It is commonly used for tasks like logging, updating values, or performing side effects.
What is the main difference between higher-order functions and callbacks?
- Higher-order functions take functions as arguments, while callbacks are functions passed as arguments.
- Callbacks are used only in asynchronous operations.
- Higher-order functions always return a value.
- Callbacks can only be anonymous functions.
Higher-order functions are functions that take other functions as arguments, offering flexibility, while callbacks are simply functions passed as arguments to other functions.
Given a large project that requires conditional loading of modules based on runtime conditions, which module system would you prefer, ES6 Modules or CommonJS, and why?
- ES6 Modules
- CommonJS
- Both are equally suitable
- Depends on the project requirements
In a large project with conditional module loading, ES6 Modules offer advantages such as static analysis during the build process, enabling more efficient tree shaking and minimizing unused code. CommonJS, being synchronous, might introduce delays in loading modules, making it less suitable for dynamic scenarios.
_________ in ES6 Modules enables static analysis and optimization, a feature not present in CommonJS.
- Explicit Dependency Declaration
- Dynamic Dependency Resolution
- Tree Shaking
- Lazy Loading
Tree Shaking in ES6 Modules allows for the removal of unused code during the build process, leading to smaller bundle sizes. This feature is not available in CommonJS, highlighting the advantages of ES6 modules.
Inside a template literal, the expression ${a + b} will __________ the values of a and b.
- Concatenate
- Add
- Multiply
- Evaluate
The expression ${a + b} inside a template literal will evaluate the values of 'a' and 'b'. It performs the specified operation (in this case, addition) and includes the result in the string.
__________ is a common pattern for dynamically loading modules based on user interactions.
- Lazy Loading
- Eager Loading
- Preloading
- Asynchronous Loading
Lazy loading is a common pattern in which modules are loaded only when they are actually needed, often based on user interactions or certain events, optimizing performance by loading resources on-demand.
When calling a static method from another method in the same class, use the class name as a _________.
- reference
- keyword
- identifier
- namespace
In JavaScript, when calling a static method from within the same class, you use the class name as an identifier. This helps differentiate static methods from instance methods, which require an instance of the class.
When using Object.keys() on an object with Symbol keys, these keys will __________ be included in the returned array.
- always
- sometimes
- never
- based on Object type
When using Object.keys() on an object with Symbol keys, the Symbol keys will never be included in the returned array. This is because Symbol-keyed properties are not enumerable and are ignored by Object.keys().
When chaining Promises in AJAX calls, what is the purpose of returning another Promise inside a .then() method?
- To allow further chaining of asynchronous operations
- To terminate the Promise chain
- To handle synchronous operations within the Promise
- To trigger a catch block if an error occurs in the Promise chain
In JavaScript, returning a Promise inside a .then() allows for continued chaining of asynchronous operations. This enables better organization and readability of asynchronous code.
An ES6 class method can be made private by prefixing its name with __________.
- private
- this
- protected
- underscore
In ES6, a class method can be made private by prefixing its name with an underscore. This convention signals to other developers that the method is intended for internal use and should not be accessed directly from outside the class. While not providing true privacy, it serves as a convention for indicating the method's intended visibility.
When a parameter is declared with a default value, its existence in the function's arguments array will be _________.
- TRUE
- FALSE
- undefined
- nan
When a parameter is declared with a default value, its existence in the function's arguments array will be false. Default parameters do not appear in the arguments object, and accessing them through the arguments object will return undefined.