Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should all the parameters with default values must be grouped together and put at the end of the parameters list? #57

Closed
tjwudi opened this issue May 5, 2014 · 5 comments

Comments

@tjwudi
Copy link

tjwudi commented May 5, 2014

Should all the parameters with default values must be grouped together and put at the end of the parameters list? What if I have a function definition like this

function foo(a, b = "", c) {}
@tjwudi tjwudi changed the title Something more about default parameters should be explained Should all the parameters with default values must be grouped together and put at the end of the parameters list May 5, 2014
@tjwudi tjwudi changed the title Should all the parameters with default values must be grouped together and put at the end of the parameters list Should all the parameters with default values must be grouped together and put at the end of the parameters list? May 5, 2014
@nzakas
Copy link
Owner

nzakas commented May 5, 2014

Are suggesting something for the book or is this just a general question?

@rwaldron
Copy link
Contributor

rwaldron commented May 5, 2014

This is allowed:

function foo(a, b = "", c) {}

This is not allowed:

function foo(a, ...b, c) {}

The original message body had an error pasted in—what was that produced by?

@getify
Copy link
Contributor

getify commented May 5, 2014

@rwaldron:

just to clarify something... if you have:

function foo(a, b = "", c) { console.log(a,b,c); }

Then you cannot set c and also invoke the default value for b right?

foo(1, void 0, 3); // 1,undefined,3    not     1,"",3

Correct?

@rwaldron
Copy link
Contributor

rwaldron commented May 5, 2014

@getify explicit undefined will invoke the default value

foo(1, void 0, 3); // 1,"",3

@getify
Copy link
Contributor

getify commented May 5, 2014

TIL. thanks @rwaldron.

@nzakas nzakas closed this as completed in 935ca97 May 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants