企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**各种数据类型颜色:** 1. 数值、布尔值:绿色 2. 字符串:黑色 3. undefined和null:灰色 ``` var age = 18; //数值 var name = 'zs'; //字符串 var pd = true; //布尔 var n; //undefined var nu = null; //null console.log(age); console.log(name); console.log(pd); console.log(n); console.log(nu); ``` ![](https://img.kancloud.cn/7b/4d/7b4de9f501dfc9a0a612becd02d8145c_642x178.png) 方法一:toString() ``` var num = 5; console.log(num.toString()); ``` **注意:undefined和null类型无法使用toString()方法** 方法二:String() ``` var num = 18; console.log(String(num)); ``` 方法三: ``` var num = 5; var b = true; console.log(num + ''); console.log(b + ''); ~~~ console.log(typeof (num + '')); //string console.log(typeof (b + '')); //string ~~~ ```