Javascript arguments vs named parameters

Posted by Joe Enos on April 25, 2021 · 1 min read
// different behavior in ES5 non-strict vs ES5 strict and ES6

function go(id, name = "jack") {
++id;
name = "bill";

// the values of the variables (2, "bill")
console.log(id);
console.log(name);

// the actual values passed in (1, "john")
// but in ES5 non-strict, they are linked to the named ones, so (2, "jack")
console.log(arguments[0]);
console.log(arguments[1]);
}

go(1, "john");