&&运算符,都为真则返回最后一个值
如c = a && b,若ab都为true,则返回后一个的值,即c=b
若写成c = b && a,则c=a
let userInfo = {username:'xxx'}
const a = userInfo.username && userInfo ;
console.log(a);
输出
let userInfo = {username:'xxx'}
const a = userInfo &&userInfo.username;
console.log(a);
输出