Can a higher-order function return another function as its output?
- Yes
- No
- Maybe
- It depends
A higher-order function can indeed return another function as its output. This feature is powerful for creating functions that can be composed and reused in different contexts.
What is the primary use case for static properties in ES6 classes?
- Improve code organization
- Enable access to class-specific information
- Facilitate class inheritance
- Enhance instance-specific functionality
Static properties in ES6 classes are used primarily to facilitate class inheritance. They allow sharing of properties among all instances of a class and provide a common base for subclasses. This improves code organization and promotes the reusability of code in an object-oriented manner.
How does the temporal dead zone affect variables declared with let and const?
- Variables become undefined
- Variables are hoisted to the top of the scope
- Variables cannot be reassigned
- Variables retain their initial value
The temporal dead zone is a phase during which variables declared with let and const exist but cannot be accessed or assigned. Attempting to use such variables before their declaration results in a ReferenceError. However, the variables are hoisted, meaning their declarations are moved to the top of the scope, but their assignments remain in place. This affects the behavior of code and is crucial to understand for avoiding bugs.
Can you use the arguments object inside an arrow function?
- Yes, arrow functions have access to the arguments object
- No, arrow functions do not have access to the arguments object
- Only if the arrow function is declared with the 'arguments' keyword
- Yes, but only in strict mode
Arrow functions do not have their own 'arguments' object. They inherit it from the enclosing scope, which may lead to unexpected behavior. Option B is correct.
When destructuring function parameters, _________ can be used to handle undefined input.
- Default parameter
- Optional chaining
- Nullish coalescing
- Early binding
When destructuring function parameters, the correct option is the "Default parameter." Default parameters in JavaScript allow you to provide a default value for a function parameter if no value or undefined is passed. This helps in handling undefined input gracefully.
In ES6, you can directly assign ________ to object properties without repeating the variable name.
- Destructuring
- Shorthand Notation
- Computed Property Names
- Arrow Functions
In ES6, destructuring allows you to directly assign values from objects or arrays to variables, making code concise and readable. Shorthand notation is commonly used for this purpose.
What is a key difference between a JavaScript Object and a Map?
- Properties order, properties, ordering, key-value pairs
- Key-value pairs, properties, ordering, properties order
- Properties order, properties, key-value pairs, ordering
- Key-value pairs, ordering, properties order, properties
In JavaScript, the key difference between an Object and a Map lies in the ability to use any data type as the key in a Map, providing a more flexible and reliable data structure for certain use cases. While Objects are limited to string and symbol keys, Maps allow any data type as keys, allowing for better handling of key-value pairs.
In ES6, what is the role of the 'package.json' file in module resolution?
- Defines dependencies and module paths
- Specifies the version of ECMAScript used
- Configures package settings
- Determines the module's entry point
The 'package.json' file in ES6 modules plays a crucial role by defining dependencies and specifying module paths. It helps in resolving modules and managing project dependencies effectively. Knowing how 'package.json' influences module resolution is essential for maintaining a well-structured project.
To handle both success and failure in an AJAX call using Promises, use .then() for success and _______ for errors.
- .error()
- .catch()
- .fail()
- .reject()
In Promises, .then() is used for success, and .catch() is used for handling errors. The .catch() method is specifically designed to handle the rejection of a promise, making it the correct choice in this scenario.
What are the implications of not calling super() in a derived class constructor?
- It has no implications
- It results in a syntax error
- It prevents the derived class from inheriting properties and methods
- It leads to a runtime error
Omitting 'super()' in a derived class constructor prevents proper initialization of the object and may lead to unexpected behavior, as the parent class constructor is not invoked. This can cause issues in inheriting properties and setting up the object's state correctly.