Primitive & Reference Types Flashcards
1
Q
What are the primitive types?
A
Number, String, Boolean, Symbol, Undefined, and Null are all primitive values.
2
Q
What are the reference types?
A
Objects, Functions, and Arrays are all reference objects.
3
Q
What is the difference between primitive and reference types?
A
Primitive values are stored in the stack, reference values like objects are stored on the heap.
Reference values know where the pointer to the value is, not the value itself. So, if the value in memory is changed the value returned by the reference type will be different
4
Q
What is the number returned to the console?
let number = 10;
function increase(number) { number++; }
increase(number);
console.log(number);
A
>>> 10
5
Q
What is the number returned to the console?
let obj = {value: 10}
function increase(obj) { obj.value++; }
increase(obj);
console.log(number)
A
>>> {value: 11}