javascript - Convert a statement to ES5 -


i need helps convert statement below es5 syntax. in es5?

const { a, b, c = “foo” } = this.props; 

i suggest use explicit check if property c exists in given object or not. if not given, use default value.

var = this.props.a,     b = this.props.b,     c = this.props.c === undefined ? 'foo' : this.props.c; 

the otherwise used pattern

c = this.props.c || 'foo'; 

does not work given falsy value zero.

why need check undefined (kudos to loganfsmyth mention problem in comments)?

because undefined value check default parameters in function in es6.

const f = (c = 'foo') => console.log(c);    f();          // 'foo'  f(undefined); // 'foo'  f(0)          // 0


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -