Zlog
首页时间轴关于
Zlog

一个探索技术、编程和构建 Web 的个人空间。

© 2026 Zlog

导航

首页时间轴关于

链接

首页/Js之 toString() 和 String() 的区别

Js之 toString() 和 String() 的区别

Js之 toString() 和 String() 的区别

Z

Zephyr110

2019年7月5日·1 分钟
|
frontendfrontend-javascript

1. null, undefined 没有 toString 方法

举例说明

js
Eg1:
console.log([1,2,3,4].constructor.toString().indexOf("Array") > -1 );//
console.log(String([1,2, 3,4].constructor).indexOf("Array") > -1);
 
返回
True
True
 
==============
 
Eg2:
var test = null;
var test_1;
  // String()
console.log(String(test));
console.log(String(test_1));
 
  // toString()
console.log(test.toString());
console.log(test_1.toString());
 
返回
null
undefined
TypeError: Cannot read property 'toString' of null
 

标签

frontendfrontend-javascript

评论

相关文章

Facade

外观模式:就是提供一个统一的接口去访问多个子系统的多个不同的接口,为子系统中的一组接口提供统一的高层接口。使得子系统更容易使用,不仅简化类中的接口,而且实现调用者和接口的解耦。

2021年12月26日·2 分钟

Singleton

单例模式:就是在整个运行时域,一个类只有一个实例对象。

2021年12月26日·2 分钟

Function Overloading

函数名相同,函数的参数列表不同(参数个数、参数类型),根据参数的不同之行不同的操作。

2021年12月19日·2 分钟

← 返回文章列表