1. 程式人生 > >if判斷null undefined等

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>