Can a static method in a parent class be overridden in a child class?
- Yes
- No
- Depends on the method implementation
- Only if explicitly declared as override
Yes, a static method in a parent class can be overridden in a child class. However, it's important to note that static methods are associated with the class itself rather than instances, and the child class can provide its own implementation of the static method, effectively overriding the one in the parent class.
In Node.js, ES6 Modules have a different file extension (_________) compared to CommonJS modules (.js).
- .mjs
- .es6
- .es
- .node
Node.js uses the .mjs file extension for ES6 modules to differentiate them from CommonJS modules that typically use the .js extension. This helps Node.js to identify the module type and apply the appropriate module loading mechanism.
In object methods, using arrow functions can lead to issues when relying on the this keyword, as it does not bind its own this, but inherits it from the ________ scope.
- Parent
- Global
- Lexical
- Block
Arrow functions inherit the this value from their lexical scope, which means the scope in which they were defined. This can lead to unexpected behavior when used in object methods.
Consider a library with multiple utility functions; how would you structure the exports to optimize for tree shaking?
- export function util1() {} export function util2() {}
- export { util1, util2 }
- export default { util1, util2 }
- export const util1 = () => {}; export const util2 = () => {};
To optimize for tree shaking, individually exporting functions (export function util1() {}) allows dead code elimination, ensuring only the used functions are included in the final bundle.
In functional composition, the output of function ______ becomes the input of function ______.
- Output, Input, Result, Transformation
- Transformation, Input, Output, Composition
- Result, Transformation, Input, Output
- Composition, Result, Output, Input
In functional composition, the output of one function serves as the input for the next one. This is a key concept in functional programming, where functions are chained together to perform a series of transformations on data.
When iterating over a Map object with a for...of loop, each iteration returns an array where the first element is the _______ and the second is the value.
- key
- index
- property
- length
In a Map object, the first element of the array returned during iteration represents the key, and the second element represents the corresponding value.
The concept of ________ is essential in understanding how functions are combined in functional composition.
- Closure
- Immutability
- Prototypes
- Referential transparency
The concept of referential transparency is essential in understanding how functions are combined in functional composition. Referential transparency means that a function, given the same inputs, will always return the same output, allowing for easier reasoning about the behavior of composed functions.
In ES6, how does the shorthand for method properties affect the 'function' keyword in object literals?
- It removes the need for the 'function' keyword.
- It enforces the use of the 'function' keyword.
- It modifies the behavior of the 'function' keyword.
- It's not related to the 'function' keyword.
In ES6, the shorthand for method properties allows omitting the 'function' keyword when defining methods in object literals. It enhances code readability by providing a more concise syntax for method definitions within objects. This syntactic sugar simplifies the declaration of methods in objects, making the code cleaner and more modern.
How does the static structure of ES6 Modules aid in tree shaking compared to CommonJS?
- Easier debugging due to explicit dependencies
- Improved dead code elimination
- Faster runtime performance
- Better support for dynamic imports
ES6 Modules have a static structure, allowing tools to analyze dependencies at build time. Tree shaking is the process of eliminating dead code, and ES6 Modules excel in this regard, making it easier to eliminate unused code during bundling.
To execute multiple async functions in parallel and wait for all of them, use __________.
- Promise.all()
- Promise.race()
- Promise.parallel()
- Promise.sequence()
To execute multiple asynchronous functions concurrently and wait for all of them to complete, the appropriate method is Promise.all(). It takes an array of promises and resolves when all the promises in the array have resolved. Promise.race() would resolve as soon as any of the promises in the array resolves, which might not be suitable for waiting for all of them. Understanding the correct usage of Promise.all() is crucial for efficient handling of parallel asynchronous tasks.
The super keyword in static methods refers to the _______ class's static methods and properties.
- Parent
- Child
- Sibling
- Derived
In a static method, super refers to the parent class's static context. This is useful for accessing static methods or properties of the parent class.
If a default parameter references another parameter, what order must they be declared in?
- After the parameter it references
- Before the parameter it references
- It doesn't matter
- They must be declared in a separate function
In JavaScript, default parameters are evaluated at the time of the function call. Explanation should cover the order of declaration and how the referencing works.