Javascript arguments vs named parameters

// 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");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s