gpt4 book ai didi

javascript - 检查 null 的条件语句不起作用

转载 作者:行者123 更新时间:2023-12-01 00:22:12 25 4
gpt4 key购买 nike

我有一个名为 header 的变量,该变量为 null 并且 typeof header 显示 string。但是,它不满足以下任何条件:

        const header = request.request ? request.request.headers.authorization : request.connection.context.Authorization
if(header == '' || header == null || header == undefined || header == false || header == 0 || header == NaN || !!header) {
console.log("Condition met")
}

似乎没有更多的方法来限定null。发生什么事了?

最佳答案

如果它的typeofstring,并且它包含null,那么它就是字符串'null'。添加:

if (header === 'null' || ...

关于javascript - 检查 null 的条件语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314799/

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