04Null和Undefined

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <script>
        /**
         * Null(空值)) 类型的值,只有一个,就是Null
         * Null 这个值专门用来表示一个为空的对象
         * 使用typeof 检查一个null值时,会返回object
         * Undefined(未定义) 类型的值,只有一个,就是Undefined
         * 当声明一个变量,但不给赋值时,变量的值就是Undefined
         */
        var a = null;
        var a = 'null';
        console.log(a);
        console.log(typeof a);
        var b ;
        // undefined
        console.log(b);
        console.log(typeof b);
        // 未定义会报错
        /**
            未捕获的引用错误:未定义c
            Uncaught ReferenceError: c is not defined
        */
        console.log(c);
    </script>
</head>
<body>

</body>
</html>
原文地址:https://www.cnblogs.com/anyux/p/14683462.html