In a for...of loop, using let allows each iteration to have its own _________ scope.
- Global
- Block
- Local
- Function
The let keyword creates a block-scoped variable, so each iteration in a for...of loop has its own block scope. This helps prevent unintended variable hoisting and makes the code more predictable.
Can you use destructuring assignment to assign default values to variables?
- Yes
- No
- Only for primitive data types
- Only for arrays
Yes, destructuring assignment in ES6 allows you to assign default values to variables. If the assigned value is undefined, the variable takes the default value specified. This feature enhances flexibility in handling variable assignments.
What happens when you try to import a non-existent named export from a module?
- It will result in an error at runtime.
- It will import the default export instead.
- It will create an empty object for the named export.
- It will import all exports from the module.
If you try to import a non-existent named export, it will result in an error at runtime. It's important to ensure that the named exports you are trying to import actually exist in the module.
How does ES6 handle importing a module that is located in a node_modules folder?
- Looks for the module in the current directory first, then checks the node_modules folder
- Directly looks in the node_modules folder
- Prioritizes searching in the node_modules folder before checking the current directory
- Searches both the current directory and the node_modules folder simultaneously
In ES6, when importing a module, the resolution algorithm prioritizes searching the node_modules folder before checking the current directory. This allows for better organization of dependencies and avoids naming conflicts with local modules. It simplifies the module import process and enhances code maintainability by following a standardized approach to handle third-party libraries.
ES6 arrow functions can make recursive functions more concise and _________.
- Readable
- Performant
- Maintainable
- Shorter
ES6 arrow functions, with their concise syntax, can make recursive functions shorter and more readable by eliminating the need for the 'function' keyword and providing implicit returns.
Using __________ at the beginning of an async function can help catch synchronous errors.
- try/catch
- await
- throw
- catch
Placing a try/catch block at the beginning of an async function allows you to catch and handle synchronous errors within the asynchronous context. This is important for comprehensive error handling in asynchronous code.
Currying in JavaScript can help in creating functions that are ________ to specific scenarios.
- General
- Flexible
- Limited
- Specialized
Currying in JavaScript can help in creating functions that are specialized to specific scenarios. Currying is a technique where a function with multiple arguments is transformed into a series of functions, each taking a single argument. This enables creating more specialized functions tailored to specific use cases.
How does 'this' behave within a static method?
- Refers to the instance calling the static method
- Refers to the class itself
- Points to the prototype of the class
- Is undefined
Within a static method, 'this' refers to the class itself, not an instance. This is because static methods are called on the class, not on instances, and they operate on class-level functionality. Therefore, 'this' inside a static method points to the class constructor, allowing access to static properties and methods.
How can you create a custom iterable object using ES6 classes?
- Implement a next method with iterator protocol
- Use the Iterable interface
- Add a getIterator method
- Set the isIterable property to true
In ES6, custom iterable objects are created by implementing the next method with the iterator protocol. This method should return an object with the value and done properties. This allows the object to be iterated using a for...of loop.
What considerations should be made when handling JSON data in the response of a Fetch API call with Promises?
- Parsing JSON should be done using the .json() method.
- Directly using responseText is the preferred method.
- JSON handling is automatic; no considerations needed.
- JSON parsing is not supported in Promises.
When handling JSON data in a Fetch API call, it's crucial to use the .json() method to parse the response properly. This method returns a promise that resolves with the result of parsing the body text as JSON, ensuring proper handling of JSON data.