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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -