一、undefined
- 当想定义一个基本类型参数时,使用undefined
<body>
<script>
let config = undefined;
console.log(typeof (config));
</script>
</body>
- 没有返回值的函数,输出结果为undefined
<body>
<script>
function show() { }
console.log(show());
</script>
</body>
- 输出没有赋值的参数时,输出结果也为undefined
<body>
<script>
function show(name) {
console.log(name);
}
console.log(show());
</script>
</body>
- 输出没有定义的变量,结果为undefined
<body>
<script>
let a = 1;
console.log(typeof (f));
</script>
</body>
二、null
- 当想要定义一个引用类型的参数时,使用null
<body>
<script>
let web = null;
console.log(typeof (web));
</script>
</body>