【奇技淫巧】+

javascript中神奇的(+)加操作符
http://www.css88.com/archives/4343

<!DOCTYPE html>

<html lang="zh-CN">

<head>

    <meta charset="utf-8" />

    <title></title>

</head>

<body>

    <script>

        // 转换成毫秒数

        console.log(+new Date('2000/09/11 19:22'));



        // 16进制转换

        console.log(+'0xFF');



        // 获取当前的时间戳 相当于 new Date().getTime()

        console.log(+new Date());



        // 比 parseFloat() parseInt() 更加安全的解析字符串

        console.log(+'010');



        console.log(+null);



        // 布尔型转换为整型

        console.log(+true);

        console.log(+false);



        console.log(+'1e10');

        console.log(+'1e-4');

        console.log(+'-12');



        // 数字转换成字符串

        console.log(typeof(1 + ''));



        // 字符串转换成数字

        console.log(typeof('123' - 0));

    </script>

</body>

</html>

 

你可能感兴趣的:(【奇技淫巧】+)