4 - Data Structures: Objects and Arrays Flashcards

1
Q

How to access a property of an object?

A

Using the bracket, or a dot notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do you retrieve by accessing a property?

A

Value that property references.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which objects don’t have properties?

A

‘null’ and ‘undefined’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the return value of typeof null?

A

‘object’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a requirement for a property name so that you can access it with a dot notation?

A

It must follow the rules of the bindings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What property names do you use to retrieve values from an array?

A

Numbers. They start with ‘0’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a method?

A

Property on an object that references a function value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Conceptually, what kind of a data structure is an array?

not in the JS context

A

Stack. LIFO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a JS object in regard to what it contains?

A

Arbitrary collections of properties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to syntactically write a property name of an object which doesn’t adhere to the rules of naming a binding?

A

Using quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What purposes have braces in general?

A

To use for a set of statements and a notation for an object literal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What will be returned when you access a property that doesn’t exist on the object?

A

‘undefined’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to remove a property from an object?

A

delete obj.foo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to check if an object has a property?

A

‘a’ in object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to find all properties of an object?

A

Object.keys(obj)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to copy all properties from one object to another?

A

Object.assign(toObj, fromObj)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the return value of ‘typeof []’

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which data types are not mutable?

A

Strings, numbers, booleans, null and undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to compare if two bindings have reference to the same object?

A

let o1 = { foo: 1 }
let o2 = o1;
o1 == o2 // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Is this valid const o = { a: 1 }; o.b = 2? Why?

A

Yes.

It mutates the elements of an object and not the assignment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How is the comparison with == of two different objects called?

A

Identity comparison.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How to write classical for loop in a easier way?

A

for (let elem of collection) {

for…of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What other objects can you loop over with for..of loop?

A

Strings, objects, but iterables in general.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What do ‘unshift’ and ‘push’ do?

A

unshift -> add element from the left
push -> add element from the right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What do 'shift' and 'pop' do?
shift -> remove element on the left pop -> remove element on the right
26
What does indexOf do?
Finds the index of the first matching element. [1,2,3].indexOf(2) => 3
27
What do indexOf and lastIndexOf return when they can't find an element?
-1
28
What does lastIndexOf do?
Finds the index of the first matching element searching from the right. [1,2,3].indexOf(2) => 1
29
How Array.slice behaves?
It creates a new array from the one it was called on. [1, 2, 3, 4, 5].slice(2) => [3, 4, 5] [1, 2, 3, 4, 5].slice(2, 4) => [3, 4]
30
How many elements Array.slice takes? Which element is inclusive, and which is exclusive?
Two elements. First one is inclusive, the second one is exclusive.
31
Will this work '[1, 2, 3, 4, 5].concat(3)'?
Yes. | It can concatenate non-array values.
32
How to join two arrays using a Array function?
Array.concat.
33
Why can't you add a new property to a string?
Because strings are not objects.
34
Why do strings have properties even though they are immutable?
Because they inherit properties from String.prototype.
35
Do strings have .slice and .indexOf properties?
Yes.
36
What does String.trim do?
Removes whitespace from the start and end of the string.
37
How does String.padStart work?
'6'.padStart(4, '1') // => '1116'
38
How does String.split work?
It splits the string on a given char.
39
How does String.join work?
It doesn't exist.
40
How to repeat a string 'foo' three times?
With String.repeat => 'foo'.repeat(3)
41
How can you access letter 'x' in a string '000x00'?
'000x00'[3]
42
How can you "collect" multiple arguments to a function to a single parameter?
With rest param. function foo(...args)
43
If you have an array and want to pass its elements to a function as arguments, how do you do it?
foo(...ary)
44
Why is spread operator called so?
Because it "spreads" elements of an array in place as separate values.
45
What is the Math object by itself technically? Why is it needed?
It acts as a namespace for Math.sum, Math.sqrt etc so that the global namespace isn't polluted by those functions.
46
What does it mean to "pollute" a global namespace?
Global namespace is polluted when bindings are defined in the outer most scope. It increases the likelihood of overriding some binding.
47
How does Javascript warn you when you redeclare bindings created with var and function keyword?
It doesn't.
48
What keywords do you have to use so that Javascript warns you when you redeclare a binding?
let and const
49
What is the return value of Math.random?
A pseudorandom number between (inclusive) zero and (exclusive) one.
50
How are random numbers conceptually created considering that computers are deterministic machines?
By creating a hidden value which gets modified every time a new random number gets created.
51
What is the return value of Math.floor(8.23)?
8
52
What is the opposite of Math.floor?
Math.ceil
53
Which function will round the given fractional number up or down?
Math.round
54
What is the return value of Math.round(0.50)?
1
55
How do you ensure you always get a positive number from any given number input?
Math.abs
56
If the function accepts an array with two elements as an argument, how do you assign those elements in the function signature?
function foo([firstElemt, secondElem])
57
What is the value of binding z here 'let [z] = null'
Type error: null is not iterable
58
How many memory addresses are created with 'let o = { a: [1, 2] }'
Two. One for the object "o" and the other for the object referenced by the "a" property.
59
How do you send Javascript literal object over the network?
You can't. You have to serialize the object.
60
How do you serialize the Javascript object?
JSON.stringify
61
How do you deserialize JSON object?
There are no JSON objects. JSON is a string which is deserialized with JSON.parse.
62
What is the syntax for putting comments within JSON files?
JSON doesn't support comments.
63
Which quotes are available in JSON format?
Double quotes.
64