Values 12 Flashcards

1
Q

Name the 8 types in the ECMAScript specification.

A

object: they type of all objects (different from Object)
bigInt: type of all big integers
symbol: type of all symbols
null
undefined
number
boolean
string

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

Whats the differences between primitive values and objects ?

A

prims are atomic building blocks of data while objects are compound pieces of data. prims are compared and passed by value whereas objects are compared and passed by their identity.

ex. when comparing objects, their identities are compared whereas with primitive values their contents are compared.

besides this, they are similar. they both have properties and can be used in the same locations

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

What does it mean when someone says ‘primitives are immutable’?

A

it means that you can’t add or change the properties of a primitive.

if you try to do
const str = ‘abc’
str.length = 1

it will resolve in a ‘TypeError: Cannot assign to read only property “length”’

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

What happens in this case?
const a = {} (//a)
b = a (// b)

A

on line a an object literal is created and the reference to it’s identity is stored in variable a. on line b, b now also points to the objects data on the heap bc it has been copied.

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

What happens in this case?
const obj = {name: ‘ant’} (//a)
const obj = {}

A

on line b, obj variable no longer points to the heap location of {name: ‘ant’}.. so that old value will be garbage collected or removed from memory.

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

What is the difference between explicit and implicit type coercion.

A

explicit is when you tell the code to change the type of a value by using a function like Number(value), whereas implicit coercion is where JavaScript converts the the type of a value behind the scenes in order to be able to work with the value
const user = ‘ant’
ex. (!user)

string user gets converted into boolean true so that it can be evaluated, but we never see that process happen.

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