當須要將數字轉換成字符時,採用以下方式:"" + 1。函數
var string = 1;
console.log(typeof string);
//number
string = ''+1;
console.log(typeof string);
//string性能
從性能上來看,將數字轉換成字符時,有以下公式:("" +) > String() > .toString() > new String()。對象
String()屬於內部函數,因此速度很快。字符串
而.toString()要查詢原型中的函數,因此速度遜色一些,原型
new String()須要從新建立一個字符串對象,速度最慢。string