default value in es6 doesn't work with arrow function

babeljs, ecmascript-6, javascript

Solution

Default values only come into affect if the function is called with no argument, or with an `undefined` value. If `handleSuccessFeatureListing` is called with `null`, `null` will be passed through.

e.g.

function fn(arg = 7){
  return arg;
}

fn() === 7
fn(undefined) === 7
fn(6) === 6
fn(null) === null

so if you are getting a `null`, then it is because `null` is being passed to the function when you expected an `undefined` value.

Problem

``` handleSuccessFeatureListing = (selectedOption=7) => { console.log(selectedOption); } ``` Why selectedOption still can be null? I thought I already set 7 as the default value for the param of selectedOption?

Original source