I was watching this video that talks about Reference Vs Value In JavaScript. https://www.youtube.com/watch?v=-hBJz2PPIVE
I was really stuck on his last example here.
let c = [1,2] //0x01
console.log('c = ${c}')
add(c,3)
console.log('c = ${c}')
function add(array,element){
array = [element]
}
The output is
c = 1,2
c = 1,2
I am trying to understand why that is. Based on my understanding, the add function should allocate [element] to a second address (let's say 0x02), then reassign c to 0x02. Which means that the value of c is now the memory address 0x02, hence c = [3]. What is it that I am not understanding correctly?