Data Types Flashcards

1
Q

How are methods added to primitive data types?

A
  • “object wrappers” are created for each primitive data type temporarily
  • which provide an extra set of methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are “normal” numbers stored in JS?

A
  • 64-bit format IEEE-754
  • double-precision floating-point
  • min is -2^53 and max is 2^53
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why does 0.1 + 0.2 equal 0.30000000000000004 in JS?

A
  • 0.1 and 0.2 are endless fractions in binary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we convert values like 12pt or 100px to numbers?

A
  • parseInt / parseFloat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can we access characters in JS strings?

A
  • str[index]
  • str.charAt(index)
  • iterable via for (let char of string)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we get a substring?

A
  • slice(start, end)
  • exclusive end
  • allows negatives
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Performance of pop/push VS. shift/unshift on arrays?

A
  • pop/push fast

- shift/unshift slow

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

How to loop over elements in array?

A
  • for (let elem of arr)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens if you compare (==) an array with a primitive?

A
  • array (object) gets converted into a primitive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we get a subarray?

A
  • slice(state, end)
  • exclusive end
  • allows negatives
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does arr.sort() behave?

A
  • sorts array in-place

- default converts elements to strings

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

How can we check if value is an array?

A
  • Array.isArray()

- because using typeof returns object

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

What are iterables and iterators in JS?

A
  • basically objects that can be used in for..of loops
  • must implement a method named Symbol.iterator
  • result of objSymbol.iterator is an iterator
  • An iterator must have the method named next() that returns an object {done: Boolean, value: any}, here done:true denotes the end of the iteration process, otherwise the value is the next value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are array-likes in JS?

A
  • objects that have indexed properties and length
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do Maps and Objects differ?

A
  • both are used for storing keyed collections
  • Maps allow keys of any type, in contrast to objects where keys get converted to strings
  • size property method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are WeakMap and WeakSet in JS?

A
  • WeakMap is Map-like collection that allows only objects as keys and removes them together with associated value once they become inaccessible by other means.
  • WeakSet is Set-like collection that stores only objects and removes them once they become inaccessible by other means.
  • Their main advantages are that they have weak reference to objects, so they can easily be removed by garbage collector.