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

Comments

Popular posts from this blog

C# Record Serialization

Add timestamp to photo using ImageMagick

Read/write large blob to SQL Server from C#