APIs Flashcards

1
Q

What does “[1,2].concat(3,[4,,5])” result in?

A

A new array of “[1,2,3,4,,5]”, as concat flattens arguments that are arrays.

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

What does “[1,2,3].slice(-2, -1)” result in?

A

A new array of “[2]”

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

What does “[1,2,3].slice(-2)” result in?

A

A new array of “[2, 3]”

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

When is an array property name an index to an element?

A

If “ToString(ToUint32(P))” is equal to “P” and “ToUint32(P)” is not equal to (2^32)−1. (i.e. an integer where 0 < MaxUInt32).

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

What is the maximum length of an array?

A

(2^32) - 1. (i.e. MaxUInt32)

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

What is the behavior of “Array” when called as a function or a constructor?

A

The same in either case. When called with a single number argument, returns a new Array with that many elements, else returns a new Array with the initial elements set to the arguments given.

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

What does “new Array(-5)” return?

A

It throws a RangeError exception.

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

How can you test if an object is an Array?

A

“Array.isArray(obj)”. This tests if the “[[class]]” internal property is ‘Array’, so it is not true for ‘array like’ objects.

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

What do “[,’a’,’b’].join(‘-‘)” and “[0,1].join()” return?

A

“-a-b” and “0,1” respectively.

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

What does “[].pop()” return?

A

undefined

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

How does Array.prototype.pop work?

A

It returns the (length-1) element from the array (this) and removes it from the array.

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

How does Array.prototype.push work?

A

Adds the arguments given to the end of the array (this), and returns the new length.

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

How does Array.prototype.reverse work?

A

It reverses the elements of the array in place, and returns a reference to the array.

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

How would you get the first element from an array ‘arr’ and remove it from the array (sliding other elements down by 1)?

A

“arr.shift()”

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

If arr = [‘a’,’b’,’c’,’d’], what does “arr.slice(-2, -1)” do?

A

Returns a new array [‘c’]. The original array is unchanged

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