如何将对正在定义或未定义的变量的检查强制转换为读取True或False的字符串

How can I coerce a check for a variable being defined or not into a string reading True or False?

本文关键字:转换 读取 字符串 False True 检查 变量 定义 未定义      更新时间:2023-09-26

我有这样设置的控制台日志:

console.log("getTestStatusActions" + this.userTestStatusActions === undefined);

这会输出一个单词"False"。

我如何使这个输出为:

"getTestStatusActions: userTestStatusActions defined"

"getTestStatusActions: userTestStatusActions undefined"

三元!

console.log("getTestStatusActions" + (this.userTestStatusActions === undefined ? "undefined" : "defined"));

或者,为了可读性:

var status = this.userTestStatusActions === undefined ? "undefined" : "defined";
console.log("getTestStatusActions: userTestStatusActions " + status);