JavaScript Curly braces argument as function parameter [duplicate]

喜你入骨 提交于 2019-12-05 05:29:38
Quentin Roy

This is an ES2015 (also called ES6) shorthand to create objects.

{ product } is equivalent to { product: product }.

Basically, you end up with an object with a property called "product" that has the value of the product variable.

const prop = "prop value";
const obj = { prop, anotherProp: "something else" }
console.log("obj: ", obj);

Have a look at the MDN documentation and here if you need a more detailed explanation.

It is a relatively new syntax so old browsers (e.g. IE) are likely to raise a syntax error, however it starts to be quite well supported amongst modern browsers. Have a look here for the ES2015 compatibility table.

This is ES6 shorthand syntax for defining object having same key as the variable name.

{product} is same as { product: product }.

Property Shorthand

MDN Docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!