本文主要是介绍js数据类型转换-----统一转成字符串String(),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
String()
所有类型都可以转成字符串
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script>//1.数值转字符串String()var a = 100var b = String(a)console.log(a,typeof a,b,typeof b)// 2.true或false或undefined转字符串var c = truevar d = String(c)console.log(typeof c,typeof d)var e = undefinedvar f = String(e)console.log(typeof e,typeof f)// 3.toString方法 null和undefind转不了var g = 100var h = g.toString()console.log(g,typeof g,h,typeof h)//4.用+号var i = 100var j = i+""console.log(j,typeof j)</script>
</head>
<body></body>
</html>
这篇关于js数据类型转换-----统一转成字符串String()的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!