js字符变量判空

测试代码:

        var params1 = '';
        var params2 = null;
        var params3;
        alert(typeof params1); // string
        alert(typeof params2); // object
        alert(typeof params3); // undefined
        alert(typeof params4); // undefined

结论:

根据上述代码可得出严格意义上的js字符变量判空条件:

  if (typeof params != 'undefined' && params != null && params != '');

posted @ 2019-09-21 18:52  NightsYoung  阅读(736)  评论(0编辑  收藏  举报