if判断null undefined等

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script>
            let a = '';

            if (!a && typeof a == 'object') {
                alert('是个null');
            } else if (!a && typeof a == 'undefined') {
                alert('是个undefined');
            } else if (!a && typeof a == 'string') {
                alert('是个空字符串');
            } else {
                alert('其他');
            }
        </script>
    </head>
    <body>

    </body>
</html>

 

posted @ 2019-01-13 09:41  我爱大西瓜  阅读(593)  评论(0编辑  收藏  举报