ES6 JS Set Default Parameters for Your FunctionsPassed

const increment = (number, value=1) => number + value || number+1;

                          <<<  `|| number+1;`  >>>

the code work but it wrong

Set Default Parameters for Your FunctionsPassed (js)

What do you think this code should do? Use of the || operator in this way can be tricky and it might not do what you expect.

I imagine we could add an increment(-5, 5) if we want this code to not pass the tests

but why have you added the OR operator there?

1 Like

the challenge it says
The result of increment(5) should be 6 . in the
so I just add || number+1;

technically works but fundamentally it not correct

But why did you add the OR? You only need to add a default parameter and that’s it.

technically works but fundamentally it not correct

Why did you add the OR? Are you just trying to find a way to break the tests and provide a slightly broken answer that passes the test suite?

cuz it says
The result of increment(5) should be 6 . in the

I just want to know what is the correct way

That does not mean you need to add an OR. That means that you need to set the default value of the value parameter.

The correct way is what you wrote but with the OR removed. The purpose of this challenge is practicing setting default values for function parameters.

it is 6, but not becouse of the || number+1 part
it is 6 because of the default parameter, this:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.