What is a key difference between a JavaScript Object and a Map?
- Properties order, properties, ordering, key-value pairs
- Key-value pairs, properties, ordering, properties order
- Properties order, properties, key-value pairs, ordering
- Key-value pairs, ordering, properties order, properties
In JavaScript, the key difference between an Object and a Map lies in the ability to use any data type as the key in a Map, providing a more flexible and reliable data structure for certain use cases. While Objects are limited to string and symbol keys, Maps allow any data type as keys, allowing for better handling of key-value pairs.
In ES6, what is the role of the 'package.json' file in module resolution?
- Defines dependencies and module paths
- Specifies the version of ECMAScript used
- Configures package settings
- Determines the module's entry point
The 'package.json' file in ES6 modules plays a crucial role by defining dependencies and specifying module paths. It helps in resolving modules and managing project dependencies effectively. Knowing how 'package.json' influences module resolution is essential for maintaining a well-structured project.
To handle both success and failure in an AJAX call using Promises, use .then() for success and _______ for errors.
- .error()
- .catch()
- .fail()
- .reject()
In Promises, .then() is used for success, and .catch() is used for handling errors. The .catch() method is specifically designed to handle the rejection of a promise, making it the correct choice in this scenario.
What are the implications of not calling super() in a derived class constructor?
- It has no implications
- It results in a syntax error
- It prevents the derived class from inheriting properties and methods
- It leads to a runtime error
Omitting 'super()' in a derived class constructor prevents proper initialization of the object and may lead to unexpected behavior, as the parent class constructor is not invoked. This can cause issues in inheriting properties and setting up the object's state correctly.
How does the temporal dead zone affect variables declared with let and const?
- Variables become undefined
- Variables are hoisted to the top of the scope
- Variables cannot be reassigned
- Variables retain their initial value
The temporal dead zone is a phase during which variables declared with let and const exist but cannot be accessed or assigned. Attempting to use such variables before their declaration results in a ReferenceError. However, the variables are hoisted, meaning their declarations are moved to the top of the scope, but their assignments remain in place. This affects the behavior of code and is crucial to understand for avoiding bugs.
How does the spread operator assist in merging and overriding properties of multiple objects?
- It creates a shallow copy of the objects and combines their properties.
- It performs a deep merge of the objects' properties.
- It only merges properties at the top level of the objects.
- It only works with objects of the same type.
The spread operator creates a shallow copy of the objects, meaning it only copies the top-level properties. It assists in merging by combining these properties, but it does not perform a deep merge of nested properties.
Which method is used to access the properties of an object's prototype?
- Object.prototype.get()
- Object.keys()
- Object.prototype.getProperty()
- Object.getOwnPropertyNames()
To access the properties of an object's prototype, the Object.keys() method is commonly used. It returns an array of a given object's property names, including properties inherited from its prototype chain.
When a generator function is called, what is returned?
- Generator object
- Array
- Promise
- String
When a generator function is called, it returns a Generator object. This object can be used to control the execution of the generator using methods like next(). Options b), c), and d) are incorrect as they do not represent the result of calling a generator function.
One primary difference between WeakMap and Map is that WeakMap keys are ________ to garbage collection.
- Referenced
- Immutable
- Strongly bound
- Weakly bound
In a WeakMap, the keys are weakly held, meaning that they don't prevent the referenced objects from being garbage collected. This is particularly useful when using objects as keys, as it allows them to be garbage collected when they are no longer needed.
For side effects only, without importing any variables, use import _________ from 'module-name'.
- { sideEffect }
- sideEffect
- * as sideEffect
- sideEffect as default
In this scenario, the correct option is c) * as sideEffect. This syntax allows importing all exports from the 'module-name' without explicitly naming them.