[英]Is it possible to get the two values from conditional(ternary) operator in javascript?
[英]Is it possible to write two values if the condition in the ternary operator is not satisfied
我有一個三元運算符
let { a, b } = data ? getData(data ) : {'', ''};
我可以將兩個空值寫入變量嗎?
在:
,放置一個對象,其中a
和b
屬性為null
:
let { a, b } = data ? getData(data ) : { a: null, b: null };
如果重復性略低,則可以在=
的左側使用默認值,如果默認的getData
的對象值不是undefined
:
let { a = null, b = null } = data ? getData(data ) : {};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.