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.
How does recursion differ from iteration in JavaScript?
- Recursion is more memory-efficient
- Recursion uses a stack, while iteration uses a loop
- Recursion is slower than iteration
- Recursion is not supported in JavaScript
Recursion involves a function calling itself, creating a stack of function calls. In contrast, iteration uses loops for repetitive tasks. Understanding these differences is essential in choosing the right approach.
A common use case for currying is to create more _________ versions of existing functions.
- Specialized, Generalized, Efficient, Complex
- Efficient, Complex, Generalized, Specialized
- Complex, Generalized, Specialized, Efficient
- Specialized, Efficient, Generalized, Complex
Currying allows the creation of more generalized versions of functions. By partially applying arguments, you can reuse and specialize functions for various scenarios.
Is it possible to declare a variable with let or const in a for-loop and access it outside of the loop?
- Yes, you can access it outside the loop
- No, it's not accessible outside the loop
- Only let variables are accessible
- Only const variables are accessible
Variables declared with let or const in a for-loop are accessible outside of the loop in which they are declared. They have block scope, which means they are confined to the nearest enclosing curly braces, allowing them to be accessed outside the loop.
__________ 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.
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.
_________ 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.