最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】js中判断变量是否为空

JS crifan 2629浏览 0评论

js check variable empty

Is there a standard function to check for null, undefined, or blank variables in JavaScript? – Stack Overflow

javascript – How to check if a value is not null and not empty string in JS – Stack Overflow

javascript – How to check if a value is not null and not empty string in JS – Stack Overflow

Checking for undefined, null, and empty variables in JavaScript | David Calhoun

【总结】

最后是

<code>if( jsVariable ) {

}
</code>

 可以实现相反的:

判断变量是否不为空,不是:

  • null

  • undefined

  • NaN

  • empty string (“”)

  • 0

  • false

所以想要判断不为空,则可以:

<code>if ( jsVariable ) {

} else {
    // do what you want to do
}
</code>

比如:

此处当http的response是空时,提示用户名或密码出错:

转载请注明:在路上 » 【已解决】js中判断变量是否为空

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.178 seconds, using 22.05MB memory