4.8js数据类型转换

var num = 10
var num1 = parseInt('123');                //字符串转换为数字
var num2 = parseInt('-123');               //字符串转换为数字,值为-123
var num3 = parseInt('12a3');               //字符串转换为数字,值为12
var num4 = parseInt('a12a3');              //字符串转换为数字,值为NaN
var num5 = Number(null);                   //null转换为数字,值为0
var num6 = Number(undefined);              //undefined转换为数字,值为NaN
var num7 = Number(true);                   //boolean转换为数字,true值为1,false值为0
var num8 = Number('');                     //''转换为数字,值为0
var num9 = parseFloat('1.23')              //字符串转换为小数
var str1 = num.toString()                  //数字转换成字符串
var str2 = true.toString()				   //boolean转换成字符串

var boolean1 = Boolean('')                 //空字符转换成boolean,值为false
var boolean2 = Boolean(null)               //null转换成boolean,值为false
var boolean3 = Boolean(undefined)          //undefinedl转换成boolean,值为false
var boolean4 = Boolean(0)                  //0转换成boolean,值为false
var boolean5 = Boolean(NaN)                //NaN转换成boolean,值为false

你可能感兴趣的:(javaScript学习笔记,javascript,前端,开发语言)