undefined与null有何本质区别?

2026-05-17 05:240阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计809个文字,预计阅读时间需要4分钟。

undefined与null的使用方法和区别,你还记得吗?

一、undefined的基本使用

1.在JavaScript中,undefined表示变量未定义,只有单一的字面值undefined,返回类型也是undefined。

- 变量未定义:`let a; console.log(a); // undefined` - 函数返回值未定义:`function test() { return; } console.log(test()); // undefined`

2. 出现undefined的四种情况 - 变量未定义:如上例。 - 函数未定义:`console.log(b); // undefined` - 函数参数未传值:`function test(a) { console.log(a); } test(); // undefined` - 函数默认参数:`function test(a=1) { console.log(a); } test(); // 1`(这里a被默认值1替代)

undefined和null的使用方法和不同你还记得吗 一、undefined的基本使用

1.在 JavaScript 中, undefined表示变量不存在,只有唯一字面值undefined,返回类型也是undefined

阅读全文

本文共计809个文字,预计阅读时间需要4分钟。

undefined与null的使用方法和区别,你还记得吗?

一、undefined的基本使用

1.在JavaScript中,undefined表示变量未定义,只有单一的字面值undefined,返回类型也是undefined。

- 变量未定义:`let a; console.log(a); // undefined` - 函数返回值未定义:`function test() { return; } console.log(test()); // undefined`

2. 出现undefined的四种情况 - 变量未定义:如上例。 - 函数未定义:`console.log(b); // undefined` - 函数参数未传值:`function test(a) { console.log(a); } test(); // undefined` - 函数默认参数:`function test(a=1) { console.log(a); } test(); // 1`(这里a被默认值1替代)

undefined和null的使用方法和不同你还记得吗 一、undefined的基本使用

1.在 JavaScript 中, undefined表示变量不存在,只有唯一字面值undefined,返回类型也是undefined

阅读全文