4 - Data Structures: Objects and Arrays Flashcards
How to access a property of an object?
Using the bracket, or a dot notation.
What do you retrieve by accessing a property?
Value that property references.
Which objects don’t have properties?
‘null’ and ‘undefined’
What is the return value of typeof null
?
‘object’
What is a requirement for a property name so that you can access it with a dot notation?
It must follow the rules of the bindings.
What property names do you use to retrieve values from an array?
Numbers. They start with ‘0’.
What is a method?
Property on an object that references a function value.
Conceptually, what kind of a data structure is an array?
not in the JS context
Stack. LIFO
What is a JS object in regard to what it contains?
Arbitrary collections of properties.
How to syntactically write a property name of an object which doesn’t adhere to the rules of naming a binding?
Using quotes.
What purposes have braces in general?
To use for a set of statements and a notation for an object literal.
What will be returned when you access a property that doesn’t exist on the object?
‘undefined’
How to remove a property from an object?
delete obj.foo
How to check if an object has a property?
‘a’ in object
How to find all properties of an object?
Object.keys(obj)
How to copy all properties from one object to another?
Object.assign(toObj, fromObj)
What is the return value of ‘typeof []’
object
Which data types are not mutable?
Strings, numbers, booleans, null and undefined
How to compare if two bindings have reference to the same object?
let o1 = { foo: 1 }
let o2 = o1;
o1 == o2 // true
Is this valid const o = { a: 1 }; o.b = 2? Why?
Yes.
It mutates the elements of an object and not the assignment.
How is the comparison with == of two different objects called?
Identity comparison.
How to write classical for loop in a easier way?
for (let elem of collection) {
for…of
What other objects can you loop over with for..of loop?
Strings, objects, but iterables in general.
What do ‘unshift’ and ‘push’ do?
unshift -> add element from the left
push -> add element from the right
What do ‘shift’ and ‘pop’ do?
shift -> remove element on the left
pop -> remove element on the right