[英]how does console.log work with functions without return value
即使assignEvent 函数只是分配而不返回任何值。 我仍然看到在下面的代码中打印了值。 为什么它在下面的代码中打印 19.99?
let event = {
name: "hot dog and burger sunday",
financials: {
baseCost: "19.99",
discountsAvailable: false,
maxCost: '29.99'
},
subscribers: [
// lots of subscribers here
]
}
let eventPrice;
const assignEvent = ({financials: {baseCost: price }}) => eventPrice = price
console.log(assignEvent(event));
是的,它确实返回一个值。 当你使用不带括号的箭头函数时,可以用一行函数来完成,这一行也用作 return 语句。 由于它是一个赋值,它返回赋值的值。 eventPrice = price
是您的退货声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.