加一个空串,直接转换为字符串。这是变字符串的简便方法。
var c = 123;
c = c + "";
console.log(typeof c);
c = null;
c = c + ""
console.log(c); //输出“null”
c = NaN;
c = c + "";
console.log(typeof c);//为“string"
另外,还可以利用typeof返回值获取类型字符串
//typeof 的返回值是字符串。
var result = typeof a;
console.log(result); //输出类型字符串“number"
另外,对于减、×÷的强制类型转换如下图