If a class extends another class, the constructor of the child class must call _______ to access the parent's properties.
- super()
- parent()
- this()
- extend()
If a class extends another class, the constructor of the child class must call super() to access the parent's properties. The super() function is used to invoke the constructor of the parent class, ensuring that the parent's properties are initialized correctly.
Which ES6 feature can be particularly useful in writing more readable recursive functions?
- Arrow functions
- Destructuring assignment
- Rest and spread operators
- Default function parameters
Arrow functions have a concise syntax, making the code more readable. They are particularly useful in recursive functions where brevity and clarity are crucial.
What is the default behavior of module resolution in ES6 when importing a module without specifying a file extension?
- Resolves to the module with the specified name
- Resolves to the module with the specified name, followed by ".js"
- Resolves to the module with the specified name, followed by ".mjs"
- Resolves to the module with the specified name, followed by ".json"
In ES6, when a module is imported without a file extension, the module resolution algorithm looks for the module with the specified name followed by ".js". If not found, it looks for the module with ".mjs" and then ".json". This flexibility allows developers to omit file extensions, and the resolution algorithm handles it accordingly.
An async function always returns a __________.
- Promise
- Callback
- Synchronous Value
- Undefined
In an asynchronous function, the return value is always a Promise. This allows for better handling and chaining of asynchronous operations.
In functional programming, _________ is a technique used to avoid side effects by ensuring data is not modified.
- Mutable State
- Immutability
- Asynchronous
- Prototyping
In functional programming, immutability is a technique that involves not modifying the data once it is created. This helps avoid side effects and makes functions more predictable and easier to reason about. Immutability ensures that data remains constant throughout its lifecycle.
What is the syntax to export a single function from an ES6 module?
- export function myFunction() {}
- export myFunction from 'module';
- export { myFunction };
- export default myFunction;
In ES6, to export a single function, you use the syntax export { myFunction };. This allows you to import it individually in another module. The export default is used for the default export, not a named one.
When using relative paths in ES6 module imports, what does './' and '../' signify?
- Current directory
- Parent directory
- Root directory
- Child directory
In ES6 module imports, './' represents the current directory, and '../' represents the parent directory. Understanding these path notations is crucial for correctly referencing modules within the project structure.
Can a module have both named and default exports?
- Yes, a module can have both named and default exports simultaneously.
- No, a module must choose either named or default exports.
- Modules can have multiple default exports, but only one named export.
- Named exports can only be used if there are no default exports in the module.
In ES6 modules, it's possible for a module to have both named and default exports. This flexibility allows developers to export a single main entity using default export and also export additional values using named exports.
The "sideEffects" property in package.json helps tree shaking by indicating if a module may contain _______.
- Side Effects
- Pure Functions
- Impure Functions
- Async Functions
The correct option is (b) Pure Functions. The "sideEffects" property, when set to false, informs the module bundler that the module does not have side effects, making it eligible for tree shaking. Pure functions are side effect-free functions that only depend on their input parameters, making them suitable for elimination during tree shaking.
What happens if you try to redeclare a variable declared with let in the same scope?
- It generates an error
- It assigns a new value to the variable
- It creates a new variable with the same name
- It deletes the variable
When you attempt to redeclare a variable with let in the same scope, it will generate an error. This is because variables declared with let cannot be redeclared in the same scope.