Can destructuring assignment be used with arrays, and if so, how does it differ from object destructuring?
- Yes, and it works the same as with objects
- No, destructuring can only be used with objects
- Yes, but the syntax is different from object destructuring
- Yes, and it uses square brackets for the pattern
Destructuring assignment can be used with arrays in JavaScript. However, the syntax differs from object destructuring. With arrays, square brackets are used to indicate the pattern, making it distinct from object destructuring that uses curly braces.
What is the difference in execution timing between callbacks and Promises?
- Callbacks may lead to callback hell due to nested structures, affecting the execution sequence.
- Promises execute asynchronously, allowing better control over the flow of the program.
- Execution timing is the same for both callbacks and Promises.
- Callbacks always execute before Promises.
Promises provide a more straightforward approach to asynchronous programming, allowing developers to handle execution timing more efficiently. Callbacks, especially when nested, can lead to callback hell, making it challenging to manage the sequence of operations. This understanding is crucial for developers aiming to enhance code readability and manage asynchronous tasks effectively using Promises.
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.
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.