When destructuring an array, the syntax _________ is used to skip over elements.
- ...
- ++
- //
- --
Destructuring an array in ES6 allows for skipping elements using the spread/rest syntax .... This is particularly useful when certain elements are not needed in the assignment.
If you are implementing a function that will be used as a callback, which might benefit from lexical scoping of this, what type of function would you choose?
- Arrow function
- Regular function
- Class method
- Anonymous function
Arrow functions are suitable for callbacks, as they capture the "this" value from their enclosing scope, providing a clean and concise way to maintain lexical scoping.
In a project using ES6 modules, if you need to dynamically load a module based on a user's action, which import method would you use?
- import()
- require()
- import dynamic
- import lazy
In ES6, the import() function allows dynamic loading of modules. It returns a promise that resolves to the module namespace object, allowing you to load modules conditionally or based on user actions.
When overriding a method in a subclass, use super.methodName() to call the original method from the _______ class.
- child
- parent
- subclass
- overridden
When overriding a method in a subclass, use super.methodName() to call the original method from the parent class. This allows the subclass to extend or modify the behavior of the parent method while still utilizing its functionality.
How do mixins in ES6 help in achieving multiple inheritance?
- Through Object Assignment
- Using Class Hierarchy
- Prototypal Inheritance
- Closures
Mixins in ES6 are achieved by applying the properties and methods of one object to another using object assignment. This allows a single object to inherit functionalities from multiple sources, providing a form of multiple inheritance. Mixins enhance code reuse and flexibility by allowing the composition of behavior from different objects.
In a class hierarchy, if a method is overridden, how can you call the method from the parent class?
- Using this.method()
- super.method()
- parent.method()
- class.method()
The 'super' keyword is used to call the overridden method from the parent class. It ensures that the overridden method in the subclass is bypassed, and the method from the parent class is invoked.
When creating a module that provides a primary functionality along with several auxiliary functions, how should you organize the exports?
- export default PrimaryFunction; export { auxFunc1, auxFunc2 };
- export { PrimaryFunction, auxFunc1, auxFunc2 }
- export PrimaryFunction; export auxFunc1; export auxFunc2;
- export PrimaryFunction, auxFunc1, auxFunc2;
Organizing exports with a named export for the primary functionality and auxiliary functions ensures clarity and flexibility when importing in other modules.
Can a Symbol be automatically converted to a string when concatenated with a string?
- Yes, Symbols are automatically converted to strings
- No, attempting to concatenate a Symbol with a string will result in an error
- Only if the Symbol has an associated description
- Symbols cannot be concatenated with strings
No, a Symbol cannot be automatically converted to a string when concatenated with a string. Attempting to do so will not result in an error but will create a new string that includes the Symbol's description, if available, or the string representation of the Symbol.
Iterators enable lazy evaluation, allowing elements to be processed one at a time, as opposed to ________ evaluation.
- synchronous
- asynchronous
- parallel
- concurrent
Iterators in JavaScript enable lazy evaluation, meaning elements are processed one at a time on demand, in contrast to synchronous evaluation, where all elements are processed at once. This supports more efficient resource utilization.
A const declaration ensures that the variable's __________ cannot be reassigned.
- type
- value
- identity
- scope
The correct option is 'value'. When a variable is declared with 'const' in JavaScript, its value cannot be reassigned. However, it's important to note that the const declaration does not make the variable itself immutable; it only ensures that the binding of the variable to a value remains constant.
When you extend a class in ES6, what must you do before using this in the constructor?
- Initialize the subclass properties
- Call the super() method
- Import the parent class
- Define a new constructor
In ES6, when extending a class, you must call super() in the constructor of the subclass before using this. The super() call initializes the properties of the parent class.
How can you access both the index and value of an array element in a for...of loop?
- for (let [index, value] of array.entries())
- for (let {index, value} of array.entries())
- for (let (index, value) of array.entries())
- for (let index, value of array.entries())
In a for...of loop, you can use the entries() method on the array to access both the index and value. The returned value is an array where the first element is the index and the second element is the value. This destructuring assignment allows easy access to both index and value.