Welcome to my website, have a nice day!
Dream it, Do it, Make it!

Javascript中如何判断变量是否为undefined/null/blank?

js.jpg

针对Boolean,Null,Undefined,Number,String这5中原始数据类型,可以使用下面的方法判断:

if(val){
    //Boolean类型为true时,非Null时,非Undefined时,Number类型大于0时,String类型不是空字符串string("")时会进入方法
}

参考文章:

  1. JavaScript 数据类型和数据结构
  2. JS数据类型分类和判断
  3. Is there a standard function to check for null, undefined, or blank variables in JavaScript?
赞(0)
未经允许禁止转载:Ddmit » Javascript中如何判断变量是否为undefined/null/blank?

评论 抢沙发

登录

找回密码

注册