Objects and OOP Flashcards
(10 cards)
How to access an object’s property?
Dot notation: obj.property
Bracket notation: obj[“property”] or obj[variable]
How to delete a property?
delete obj.property
How to check, if a property with a given key exists?
“key” in obj
How to iterate over an object?
for (let key in obj)
How are objects saved?
They are stored in memory by reference. The variable does not store the value but the reference for the value.
How to copy an object?
Object.assign() or _.cloneDeep(obj)
What are methods?
Functions stored in objects.
How can methods reference the object?
With the keyword “this”.
What is “this”?
A special variable defined at run-time. Most of the time it’s referencing to the object “left of the dot”.
What is so special about arrow functions and “this”?
Arrow functions do not have “this”. A “this” inside an arrow function references to the outer scope.