GitHub 博客园 Nanakon

【奇技淫巧】+

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>

 

posted on 2013-03-26 14:33  jzm17173  阅读(100)  评论(0编辑  收藏  举报

导航

轻音