将代理设置为空字符串与未定义之间有区别吗?
Is there a difference between setting a proxy to an empty string vs undefined?
如果没有 process.env.HTTPS_PROXY 与空字符串相比,代理未定义会出现什么问题?
const proxy = process.env.HTTPS_PROXY || '';
对
const proxy = process.env.HTTPS_PROXY;
问题是你之后做了什么:
假设 process.env.HTTPS_PROXY
未定义:
const proxy = process.env.HTTPS_PROXY || '';
if (proxy.length > 7){
// something
} else {
// something else
}
只需输入“其他”部分
const proxy = process.env.HTTPS_PROXY;
if (proxy.length > 7){
// something
} else {
// something else
}
会抛出Uncaught ReferenceError: proxy is not defined
并可能使您的应用程序崩溃
如果没有 process.env.HTTPS_PROXY 与空字符串相比,代理未定义会出现什么问题?
const proxy = process.env.HTTPS_PROXY || '';
对
const proxy = process.env.HTTPS_PROXY;
问题是你之后做了什么:
假设 process.env.HTTPS_PROXY
未定义:
const proxy = process.env.HTTPS_PROXY || '';
if (proxy.length > 7){
// something
} else {
// something else
}
只需输入“其他”部分
const proxy = process.env.HTTPS_PROXY;
if (proxy.length > 7){
// something
} else {
// something else
}
会抛出Uncaught ReferenceError: proxy is not defined
并可能使您的应用程序崩溃