I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (
</>) will also add backticks around text.
When arrays or objects are assigned to a variable, only a reference is passed to the variable. See below for explanations of what is happening at each stage of your code.
var curr = [
['ONE HUNDRED', 100]];
var result = ;
var a = curr; // Initialize variable a to refer to an array (curr or ['PENNY', 0.01])
console.log(a); // displays [ 'PENNY', 0.01 ] because a refers to curr
console.log(result); // displays [ [ 'PENNY', 0.01 ] ]
// since a is just a reference to curr it is like curr was pushed into result
result = 0; // this is changing the curr's 2nd element to 0 because result is the value of a which is a reference to curr
console.log(curr); // displays [ 'PENNY', 0 ]
// Notice below how I can use the a variable to modify the first element of curr;
a = 'CHICKEN';
console.log(curr); // displays [ 'CHICKEN', 0 ]