gpt4 book ai didi

javascript - 使用逻辑运算符如何填充 var?

转载 作者:行者123 更新时间:2023-11-30 16:44:23 25 4
gpt4 key购买 nike

<分区>

让我们看一下这段代码:

var token = (req.body && req.body.access_token) ||
(req.query && req.query.access_token) ||
req.headers['x-access-token'];

Taken from here.

这不应该返回一个 bool 值吗?最让我困惑的是链式 AND 和 OR 语句。我正在读这个:

The variable token equals the boolean whether req.body AND req.body.access_token exist. OR, if they don't exist, then it equals the boolean whether req.query AND req.query.access_token exist. OR, if they don't exist, it equals the value of req.headers['x-access-token'].

此外,如果我们只分析这一 block :

var token = req.body && req.body.access_token;

是什么阻止了 token 被设置为 req.body

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com