码迷,mamicode.com
首页 > Web开发 > 详细

js简单语法,循环

时间:2020-05-01 16:44:30      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:nan   使用   blog   语法   com   false   body   获取   tle   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js grammar</title>
</head>
<body>
       
    <script>
        //1.js语法

      /*  //https://www.cnblogs.com/yuanchenqi/articles/5980312.html
        // <script src="hello.js"> 引入方式
        var a = 1;  //声明变量时不用声明变量类型. 全都使用var关键字
        var b = 2 ,c = "cc"; //一行可以申明多个变量,且不用是同类型
        alert(a / b);
        alert(b / a);
        alert(c)

        function fun() {
            var va = "this is va";
            //alert(va)
            document.write(va)
           // console.log(va)
        }
        fun()
        */
        // 2.js数据类型

        /*var a = 2;
        var b = false;
        var c = 2.1;
        var d = NaN;
        var e = undefined;
        var f = null;
        var obj = new Object();

        console.log(typeof(a));
        console.log(typeof(b));
        console.log(typeof(c));
        console.log(typeof(d));
        console.log(typeof(e));
        console.log(typeof(f));
        console.log(typeof(obj));

        var aa = "abc"+12;
        alert(aa) ; // abc12
        //在js中false,ture分别代表0,1
        var bb = 1+false;
        alert(bb);

        var cc = 2 + true;
        alert(cc);*/

/*        alert("hello"+true);

        alert(parseInt(3.14))
        alert(parseFloat("33.21"))*/

        // var a = 1;
        // alert(a++); //先赋值后加减 a = a+1   a= 1  所以a++获取的是a的值之后a=2
        // alert(a);  //2
        // alert(++a);  //3
        // alert(--a);  //2
        // alert(a--); //2
        // alert(a);  //1

       // alert(null==undefined); true
        //alert(false==0); true
        //alert(true ==1); true
        //alert(true == 2);  false
        //alert(undefined == 0); false
        //alert(5=="5");  true
        //alert(5==="5"); false
        var a = 1;
        var num = 0;
        for(a;a<=100;a++){
            num += a;
        }
        alert(num);



        a = {"aa":"bb","cc":"dd"}
        for (var i in a) {
            console.log(i);
            console.log(a[i]);
        }


         b = ["a","b","c","d"];
        for (var i in b){
            console.log(i);
            console.log(b[i]);
        }

        var a;
        switch (5){
            case 1: a = "aa"; break;
            case 2: a = "bb"; break;
            case 3: a = "cc"; break;
            default: a = "dd"; break;
        }
        alert(a)

        var c = 1;
        var counts = 0;
        while (c <=100){
            counts += c;
            c+=1;
        }
        alert(counts)



    </script>
</body>
</html>

 

js简单语法,循环

标签:nan   使用   blog   语法   com   false   body   获取   tle   

原文地址:https://www.cnblogs.com/TKOPython/p/12813791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!