Can you use the arguments object inside an arrow function?
- Yes, arrow functions have access to the arguments object
- No, arrow functions do not have access to the arguments object
- Only if the arrow function is declared with the 'arguments' keyword
- Yes, but only in strict mode
Arrow functions do not have their own 'arguments' object. They inherit it from the enclosing scope, which may lead to unexpected behavior. Option B is correct.
When destructuring function parameters, _________ can be used to handle undefined input.
- Default parameter
- Optional chaining
- Nullish coalescing
- Early binding
When destructuring function parameters, the correct option is the "Default parameter." Default parameters in JavaScript allow you to provide a default value for a function parameter if no value or undefined is passed. This helps in handling undefined input gracefully.
In ES6, you can directly assign ________ to object properties without repeating the variable name.
- Destructuring
- Shorthand Notation
- Computed Property Names
- Arrow Functions
In ES6, destructuring allows you to directly assign values from objects or arrays to variables, making code concise and readable. Shorthand notation is commonly used for this purpose.
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.
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.