标签: javascript
以下语句没有if语句,即使它使用?字符。它是如何评估的?
if
?
var username = req.user ? req.user.username : '';
答案 0 :(得分:6)
它等同于:
var username; if (req.user) { username = req.user.username; } else { username = ''; }
Read more about ternary operators on MDN