JS 数字方法和类型

复制代码
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script>
            //向上舍入
            console.log(Math.ceil(6.4));
            //向下
            console.log(Math.floor(6.4));
            //四舍五入
            console.log(Math.round(6.4));
            //随机数 返回m至n+m-1之间的数
            var n=10;
            var m=1;
            Math.floor(Math.random()*n)+m;
            //=== 值和类型都相等
            //循环
            var point={
                x:1,
                str:"str"
            };
            for(let x in point ){
                console.log(point[x]);
            }
            
            var s1="string";
            for(var c of s1){
                console.log(c);
            }
        
            //5种数据类型 
                // string number boolean object function
            //6种对象
                //Object Date Array String Number Boolean
            //2种不含值
                //null undefined
            
            //类型转化
                //转化为字符串
            String(123);
            var x=123;
            x.toString();
                //转化为数值
            Number("3.14");
            
        </script>
    </body>
</html>
复制代码

 

posted @   lwx_R  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示