Objects Flashcards
Get a fucking job
What is an object?
A data type. Enclosed by curly braced and an n number of key:value pairs.
How can a property be accessed?
- Dot property accessor: object.property
- Square brackets property accessor: object[‘property’]
- Object destructuring: const {property} = object
What is shorthand properties?
Whenever we have a variable which is the same name as a property of an object, when constructing the object, it can be omitted the property name.
function eg(name,id){
return {
name: name,
id: id,
timestamp: Date.now()
}
}
// SHORTHAND PROPERTIES
function eg(name,id){
return {
name,
id,
timestamp: Date.now()
}
}
What does the “in” operator do?
Returns true if the specified property is in the specified object or its prototype chain.
What is the prototype chain?
Every JavaScript object has an internal [[Prototype]] property. When accessing an object property, JavaScript first looks for it in the object itself. If it doesn’t find it, it will look for it in the prototype chain checking the object’s [[Prototype]]. The chain ends at Object.prototype whose [[Prototype]] is null.
What are dynamic properties?
The ability to add, modify or delete object properties at runtime.
What is destructuring?
A JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.
What is Object.values()?
Static method that returns an array of a given object’s own enumerable string-keyed property values.
What is Object.keys()?
Static method that returns an array of a given object’s own enumerable string-keyed property names.
What is Object.entries()
Static method that reutns an array of a give object’s own enumerable string-keyed property key-value pairs.
What is ??
Nullish coalescing operator. It’s a logical operator that returns its right-hand side when the left-hand side is null or undefined.
What is ?.
Optional chaining operator. If the object or function being accessed with this operator is null or undefined, the expression evaluates to undefined instead of throwing an error.
What is …
Spread syntax. Allows an iterable to be expanded in places in which zero or more arguments (for functions calls) or elements (for array literals) are expected.