JS中String()和toString()
2021-05-19 01:27
标签:不能 返回结果 eof tar .com htm 开头 get col 例如将false转为字符串类型 返回的结果为 false,string 看看null 和 undefined能不能转换为字符串javascript 结果程序报错 程序也报错 .toString() 括号中的可以写一个数字,代表进制,对应进制字符串 二进制:.toString(2); 八进制:.toString(8); 十进制:.toString(10); 十六进制:.toString(16); 如: 例如将null转换为字符串 返回的结果为 null,string 将undefined转换为字符串 返回的结果为 undefined,string JS中String()和toString() 标签:不能 返回结果 eof tar .com htm 开头 get col 原文地址:http://www.cnblogs.com/qiong2017/p/7722990.html
1、.toString()可以将所有的的数据都转换为字符串,但是要排除null 和 undefined
var str = false.toString();
console.log(str, typeof str);
"margin-right: 0px;" dir="ltr">
class="html" name="code"> var str = null.toString();
console.log(str, typeof str);
var str = undefined.toString();
console.log(str,typeof str);
2、String()可以将null和undefined转换为字符串。
var str = String(null);
console.log(str, typeof str);
var str = String(undefined);
console.log(str, typeof str);
文章标题:JS中String()和toString()
文章链接:http://soscw.com/index.php/essay/87441.html