JBT JBT - 1 year ago 101
Javascript Question

Square brackets surrounding parameter in function definition

I came across the following code in the Ember CLI website:

export default Ember.Helper.helper(function([value]) {
return value.toUpperCase();

What confuses me is the square brackets surrounding the
parameter. I can understand it in a function call, but why in function definition?

Answer Source

This is all very surprising to me, but it appears to be valid javascript, according to the ECMAScript 2017 language specification, the formal parameter in a function declaration can any "binding element", including an array binding.


The actual behavior of this feature seems to mean that the argument to the function should be an array, and value will take on the value of the first element in the array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download