For side effects only, without importing any variables, use import _________ from 'module-name'.
- { sideEffect }
- sideEffect
- * as sideEffect
- sideEffect as default
In this scenario, the correct option is c) * as sideEffect. This syntax allows importing all exports from the 'module-name' without explicitly naming them.
In ES6, what is the behavior of using super in a method when extending a class?
- Calls the superclass constructor
- References the superclass prototype
- Creates a new instance of the superclass
- Invokes the superclass method
In ES6, when using super in a method of a subclass, it refers to the superclass, allowing access to its methods and properties. It is often used to call the superclass constructor using super() or invoke methods on the superclass. This facilitates extending the functionality of the superclass.
What is the base case in a recursive function?
- The initial condition
- The stopping condition
- The recursive condition
- The iterative condition
In a recursive function, the base case is the condition that prevents further recursion. It is crucial for stopping the recursion and ensuring that the function does not enter an infinite loop.
In ES6, mixins can be created by a function that takes a _________ as an argument and extends it.
- Class
- Function
- Object
- Module
In ES6, mixins are created by a function that takes an object as an argument and extends it. This approach allows for dynamic composition, enabling the combination of functionalities from different sources into a single object.
What are the implications of using default parameters on function length property?
- The length property reflects the number of parameters without default values
- The length property includes parameters with default values
- Default parameters do not affect the length property
- The length property is no longer relevant with default parameters
When default parameters are used in a function, they do not contribute to the length property. The length property only counts the number of parameters without default values. Therefore, the length might not accurately represent the total number of arguments the function can accept.
How does the spread operator assist in merging and overriding properties of multiple objects?
- It creates a shallow copy of the objects and combines their properties.
- It performs a deep merge of the objects' properties.
- It only merges properties at the top level of the objects.
- It only works with objects of the same type.
The spread operator creates a shallow copy of the objects, meaning it only copies the top-level properties. It assists in merging by combining these properties, but it does not perform a deep merge of nested properties.
Which method is used to access the properties of an object's prototype?
- Object.prototype.get()
- Object.keys()
- Object.prototype.getProperty()
- Object.getOwnPropertyNames()
To access the properties of an object's prototype, the Object.keys() method is commonly used. It returns an array of a given object's property names, including properties inherited from its prototype chain.
When a generator function is called, what is returned?
- Generator object
- Array
- Promise
- String
When a generator function is called, it returns a Generator object. This object can be used to control the execution of the generator using methods like next(). Options b), c), and d) are incorrect as they do not represent the result of calling a generator function.
One primary difference between WeakMap and Map is that WeakMap keys are ________ to garbage collection.
- Referenced
- Immutable
- Strongly bound
- Weakly bound
In a WeakMap, the keys are weakly held, meaning that they don't prevent the referenced objects from being garbage collected. This is particularly useful when using objects as keys, as it allows them to be garbage collected when they are no longer needed.
When creating a utility class with common helper functions, how would you ensure that these methods are accessible without instantiating the class?
- Use static methods
- Use private methods
- Use public methods
- Use protected methods
In ES6, you can ensure that methods in a utility class are accessible without instantiating the class by defining them as static methods. Static methods are associated with the class itself rather than instances, allowing you to call them directly on the class without creating an object. This is beneficial for utility classes where instantiation is unnecessary, and you want to organize related functions.