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.
The spread operator can be used in ES6 to clone an array without ________ the original array.
- Modifying
- Changing
- Altering
- Mutating
The spread operator can be used to clone an array without mutating the original array. It creates a shallow copy, meaning nested objects are still references, but the outer array is a new instance.
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.
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.
Each call to the next() method on a generator returns an object with two properties: value and _________.
- result
- done
- output
- complete
The next() method on a generator returns an object with two properties: value (the yielded value) and done (a boolean indicating whether the generator has completed). The other options do not represent the properties returned by the next() method.
Imagine you are creating a gaming application with different types of characters. How would you use inheritance in ES6 classes to implement shared behaviors?
- Object Composition
- Using Mixins
- Extending Base Class
- Function Constructors
In this scenario, you would extend a base class to create subclasses for each character type. Option A is about combining objects, Option B is about sharing functionality through mixins, and Option D is an older approach not commonly used in ES6.
How can default parameters be used to create polymorphic functions in JavaScript?
- By defining multiple functions with the same name and different default parameters
- Default parameters cannot be used for polymorphism
- Utilizing default parameters for error handling
- By using default parameters to define optional arguments
Default parameters allow you to create polymorphic functions by defining multiple functions with the same name but different default parameters. This way, the function can behave differently based on the provided arguments, providing a form of polymorphism.
Q3: If you encounter a performance issue in a web application due to extensive use of prototypes, what would be your approach to optimize it?
- Utilize static methods
- Minimize prototype chain depth
- Convert prototypes to classes
- Use Object.setPrototypeOf()
To optimize performance, reducing the depth of the prototype chain is crucial. This minimizes the number of lookups required during property access, enhancing overall efficiency. It's essential to carefully design the prototype hierarchy for better performance in large-scale applications.
What is the outcome when attempting to instantiate a class without the 'new' keyword in ES6?
- It results in a runtime error
- It creates a new instance but without the class's constructor being called
- It has no impact; both 'new' and non-'new' instantiation work the same way
- It leads to a memory leak
If a class is instantiated without the 'new' keyword, it throws a runtime error. The 'new' keyword is crucial for invoking the constructor and properly creating an instance of the class.
When using const to declare a variable, what type of assignment is mandatory?
- Reassignment
- Initialization
- Increment
- Declaration
When you declare a variable with const, you must initialize it with a value. const variables cannot be declared without an initial value, and they cannot be reassigned to a different value after initialization.