In ES6, can the rest operator be used in conjunction with destructuring to extract specific elements from an array?
- Yes, the rest operator allows extracting specific elements by using the spread syntax.
- No, the rest operator can only be used to extract all elements in an array.
- Yes, the rest operator can be combined with destructuring to extract specific elements.
- No, the rest operator is not compatible with array destructuring.
In ES6, the rest operator can indeed be used in conjunction with array destructuring to extract specific elements. It allows you to capture the remaining elements of an array into a new array variable.
When using default export, you can rename the imported module without using the _________ syntax.
- import customName from
- import as customName from
- import {customName} from
- import default as customName
In ES6, when importing a module with a default export and renaming it, you use the import customName from 'moduleName'; syntax. The as keyword is not required in this context.
What method is used to resume the execution of a generator function?
- resume()
- continue()
- next()
- run()
The correct method to resume the execution of a generator function is next(). This method is called on the Generator object and proceeds to the next yield statement, returning the yielded value. Options a), b), and d) are incorrect and not used for resuming a generator function.
Tagged template literals allow you to parse template literals with a _________ function.
- Regular
- Parse
- Tag
- Transform
In ES6, tagged template literals use a tag function to parse the template literal. This function, often referred to as the tag, allows you to process the template and its interpolated values before producing the final string.
How does the 'use strict' mode affect class behavior in ES6?
- It enforces stricter type checking in class properties
- It allows for dynamic addition of properties in a class
- It has no impact on class behavior
- It throws an error if the class contains undeclared variables
In 'use strict' mode, the class behavior becomes more rigid. It disallows the usage of undeclared variables, ensures that the 'this' keyword behaves more predictably, and generally promotes safer coding practices.
If a property is not found on an object, JavaScript looks up the property on the object's prototype, known as the _________ chain.
- Prototype
- Scope
- Inheritance
- Execution
In JavaScript, the process of searching for a property involves traversing the prototype chain. If the property is not found on the object, it looks up in the prototype chain until it finds the property.
An unhandled promise rejection can be caught globally using process.on('________', handler).
- rejection
- unhandledRejection
- promiseError
- errorHandled
In Node.js, the 'unhandledRejection' event is emitted when a Promise is rejected but no handler is provided. Using process.on('unhandledRejection', handler) allows you to catch and handle such rejections globally.
What is the primary purpose of tree shaking in JavaScript modules?
- Eliminating Unused Code
- Minifying the Code
- Enhancing Code Readability
- Improving Network Performance
Tree shaking is a process in JavaScript where unused or dead code is eliminated from the final bundle during the build process. The primary purpose is to reduce the size of the bundle by removing parts of the code that are not actually used, thus improving the application's performance and loading times. It helps in optimizing the overall efficiency of the application by excluding unnecessary code.
Higher-order functions improve code __________ by allowing for more abstract and concise code.
- Efficiency
- Readability
- Performance
- Execution
By using higher-order functions, code becomes more readable and expressive. It abstracts away the details of how a particular operation is performed, making the code concise and easier to understand.
How does inheritance of static methods differ from that of instance methods in ES6?
- Static methods cannot be inherited.
- Static methods are inherited through the prototype chain.
- Static methods are inherited using the extends keyword.
- Static methods are inherited through the super keyword.
In ES6, static methods are inherited through the prototype chain, just like instance methods. The key difference lies in how they are called and accessed. The extends keyword is used to inherit static methods, making them accessible through the derived class. Option B is the correct answer.