* 一、转化为数字*/
console.log(‘123123’*1.0);
/* 二、从一个值中提取另一中类型的值,并完成转化工作 */
console.log(parseInt(‘1233zxhag’)); //1233
console.log(parseFloat(‘1.123aef’)); //1.123
console.log(eval(1+123)); //124
console.log(toString(123)); //[object Window] ‘123’
/* 将整个值从一种类型转化成另一种类型(称作基本类型转换) */
console.log(String(‘123123′));
console.log(String(null)); //null
console.log(String(undefined)); //undefined
console.log(Number(‘123123′));
console.log(Number(null)); // 0
console.log(Number(undefined)); //NaN
console.log(Boolean(123123)); //true
console.log(Boolean(null)); //false
console.log(Boolean(undefined)); //false
本文转自(http://dayney.com/?p=38)
时间: 2024-09-30 18:32:28