[英]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.