undefined
null
''
各判断一次 ):if( (this.$route.query.openid != undefined || this.$route.query.openid != null || this.$route.query.openid != '' ) && window.localStorage.getItem('openid') != '')
{
......
}
想问下 JS
或者 Vue
或者 ES
中有没有什么方法能一次性直接判断变量是否有效?
在JavaScript中,你可以使用if语句和逻辑运算符(&&)来判断一个值是否为undefined、null或空。以下是一个示例:
```javascript let myValue = undefined;
if (myValue === undefined) { console.log("myValue is undefined"); }
if (myValue === null) { console.log("myValue is null"); }
if (myValue === "") { console.log("myValue is empty"); } ```
在这个示例中,我们首先检查myValue是否为undefined。如果是,我们打印一条消息说myValue是undefined。然后,我们检查myValue是否为null。如果是,我们打印一条消息说myValue是null。最后,我们检查myValue是否为一个空字符串。如果是,我们打印一条消息说myValue是空字符串。