javascript - named variable filter syntax in redux -
i have finished learning javascript , typescript (i know redux not typescript), have been thouroughly confused syntax redux filters:
function visibilityfilter(state = 'show_all', action) { ... } i've seem default variables in javascript, when default variable after positional variable. going on here? can point me documentation explains syntax?
basically means reducer expects receive action, uses default value if first parameter undefined.
function reducer(state = 'initial', action) { if (action.type === 'change') { return 'new'; } return state; } console.log( 'uses given initial state: ', reducer('what', {}) ); console.log( 'null considered given state: ', reducer(null, {}) ); console.log( 'uses default state if first param undefined: ', reducer(undefined, {}) ); const myserverstate = undefined; console.log( 'passing undefined might not obvious: ', reducer(myserverstate, {}) ); // throws error because action undefined console.log(reducer({ type: 'change' }));
Comments
Post a Comment