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.
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.
Describe a scenario where using tagged template literals could be beneficial for sanitizing user input in a web application.
- They enable the creation of custom sanitization functions to process user input.
- They automatically escape special characters, preventing injection attacks.
- They provide a mechanism to enforce strict input validation rules.
- They allow for the easy integration of third-party sanitization libraries.
Tagged template literals allow developers to create custom sanitization functions, ensuring secure processing of user input and preventing potential injection attacks.
How are imports and exports handled differently in ES6 Modules compared to CommonJS?
- Explicit import and export statements
- Automatic global binding
- Using require and module.exports
- Implicit import and export statements
In ES6 Modules, imports and exports are explicit, and you use import and export statements to define dependencies. This is different from CommonJS, where dependencies are managed using require and module.exports.
How do you import a specific function from a module in ES6?
- import myFunction from 'module';
- import { myFunction } from 'module';
- import * as myFunction from 'module';
- import myFunction as 'module';
To import a specific function from a module in ES6, you use the syntax import { myFunction } from 'module';. This allows you to bring in only the functions or variables you need rather than the entire module.
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.
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 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.
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 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.