JS前期学习心得

时间:2022-07-03 16:21:59

        从学习JavaScript到现在已经有半个月的时间了,从简单的基础知识到现在的基础逻辑思维练习,知识点也在逐步的增加。

学习的难度也在逐步的加深。刚开始的我还能接受这些,可是随着知识点的增加,感觉自己学习起来越来越吃力,比如最近学

习的函数,在C语言阶段,我的函数就学的不是很好,应该算自己的一个难点,如今又接触到函数,还是有点儿吃力,希望自

己在后面的学习阶段能够有所改变。总的学习知识点如下:

       第一阶段:接触基础知识

                     1、JS输出方式:

                           控制台输出:

                           console.log("xxx");

                           页面输出:

                           document.write(“xxx”);

                           弹出输出:

                           alert ("xxx");

                           prompt ("xxx");

                      2、变量:

                           变量是储存数据信息的内容。

              变量是被认为是有名字的容器。使用变量名为值命名;               必须先声明一个变量,变量才能被使用;               变量是弱类型,也被称为松散型;指可以用来保存任何类型的数据;            3、变量提升:               a、先解析,获取所有被生命的变量,之后在一行一行运行。就会造成所                  有的变量声明提升到代码头部;               b、只对var命名的变量有效;     第二阶段:           1、数据类型:             JavaScript语言中每一个值,都属于某一种数据类型。            在ES5中数据类型分为六种:五种原始类型,一种引用数据类型;          2、原始类型:             a、number(数字);             b、boolean (布尔);             c、string (字符串);             d、null ;用于表示某个变量值为空。             e、undefined;用来确定一个已经创建但是没有初始值的变量。          3、数据类型转换:             a、parseInt()函数:转换成整数;             b、parseFloat ()函数:解析一个字符串,返回一个浮点数;转换成小数             c、Number :可以将任意类型的值转换成数字;          4、强制转换成字符串:             String()函数:可以将任意类型转换成字符串;          5、强制转换成布尔值:             Boolean ()函数:可以将任意类型转换成布尔值;             除了以下5个结果为false,其他得值全为true:             undefined、null、0、NaN、,,,    第三阶段:运算符         1、算术运算符:            + - * / % ++ --            ++:自动运算符,整数值逐次加1;            --:自动运算符,整数值逐次减1;            注意:                自增运算符:              前置型(++a):先执行加操作,再应用变量值。              后置型(a++):先引用变量值,再进行自加操作。         2、比较运算符:            > >= < <= == != === !===         3、逻辑运算符:            && || !            &&:一假必假            ||:一真必真         4、赋值运算符:            = += -= *= /= %=         5、字符串连接运算符:            +         6、三目运算符/条件/三元            ? :         7、特殊运算符:            typeof  instanceof    第四阶段:流程控制语句         1、三种执行语句:            a、顺序执行            b、选择执行            c、循环语句         2、条件语句:            通过判断得到的结果,来决定是执行还是跳过指定的代码。          3、if语句:             例:                var a = 3;                if (a>5){                     console.log(a);                }                console.log("xxxx");          4、if else语句:             例:              var b = 5;              if (b>10) {                    console.log("b大于10");                  }               else {                    console.log("b小于10");                 }        5、else if语句:           例:            var sum = 98;                           if (sum>90){                                        console.log("优");                            }                           else if(sum>60 && sum<90){                                        console.log("良");                            }                          else {                                       console.log("差");                           }                   6、swich case 语句:                        例:                           var a = 4;                          switch(a){                                       case 1:                                                console.log("111");                                                break;  //终止                                       case 2:                                                console.log("222");                                                 break;                                       case 3:                                                console.log("333");                                                break;                                       default: //当值未声明时,执行default                                                console.log("4444");                                                }                      7、循环语句:                           a、while 循环:                                  例:                                     var a = 1;                                    while (a<5){     先判断                                              console.log(a);      再执行                                              a++;                                                 }                                    输出结果:1、2、3、4;                           b、do while循环:                                   例:                                        var num =1;                                       do{                                            console.log(num);    先执行                                            num++;                                        }while(num < 5);   再判断                                        输出结果:1、2、3、4;                                       while与do while的区别:                                        while:先执行,再判断;                                        do while:先判断,在执行;                        for 语句:                               例:                                1、初始化表达式:初始化一个计数器,再循环开始前记录初始状态。                                2、条件判断表达式:判断给                                3、循环操作表达式:                                for (var i = 0;i < 10; i++) {                                console.log(i);                                }                                for (表达式1;表达式2;表达式3){                               表达式4(大括号里面所有代码)                               }                               执行顺序:表达式1》表达式2》表达式4》表达式3》表达式1.....                         for 嵌套语句:                                例:                                   for (var i=0;i<5;i++){                               for(var j=0;j<3;j++){                              console.log(j);                               }                              }                               break:终止当前整个循环;                            continue:终止当前这一轮循环;        第五阶段:函数:                     1、定义;                           例:                          function fn(){                                       console.log("this is a function");                          }                     2、定义方                      .  函数声明方式://函数声明function fn(){console.log("1111");}                      .  字面量方式:不存在函数提升;//字面量 (函数表达式)var fn = function(){console.log("1111");} 函数调用:fn ();               函数名+()一是点用函数;二是接受返回的值;                     3、函数参数:                             a、形参:定义函数时使用的参数;                           b、实参:调用函数时使用的参数;                     4、return语句:                             例:                         function fn (msg){                                       return "hello" + msg;                         }                         var fun = fn("world");                         console.log(fun);                         注意: return默认情况下返回的是undefined。                     5、全局作用域与局部作用域:                           函数作用域(局部作用域)                           变量作用域:指的是变量可被访问的范围。分为全局作用域和局部作用域。                            *全局作用域:一个html文档只有一个全局作用域,,任何位置都能访问                            *局部作用域:也叫函数作用域,指的就是在函数内部的区域。                           声明在全局作用域的变量就叫做全局变量,声明在局部作用域的变量叫做局部变量。                           function fn(){                                       var str = "abc";                          console.log(str);、/*写在此处才正确*/                           }                          fn();                          console.log(str);/*写在此处会出现错误*/                     6、函数提升变量:                          7、匿名函数:                            例:                    function(){                     }                         立即执行函数(自调函数);                       例:调用1                        (function (a,b){                             console.log(a+b)                         }) (1,2);                       例:调用2"                        (function(a,b){                                 console.log(a+b)                        } (2,4));                        ES6:                       函数参数的默认值 (函数的默认参数)                       例:                   function fn(a,b){                        if(a === undefined){                                 a=1;                          }                       if(b === undefined){                                  b=1;                           }                     return a+b;                       }                     console.log(fn(x,x));                       function fn(a=1,b=2){                      return a+b;                        }                     console.log(fn(x,x));                     8、箭头“”函数:                          例:                       a => a * a;                                 a => {                        if(){                           }                         else{                                    }                            }                        (a) =>{                           console.log(a);                           return;                           }                            var fn = (a) =>{                           console.log(a);                           return;                            }                           fn(1);                     注意:当箭头函数没有参数或者有多个参数             以上是最近的学习知识点,在最近几天的学习中,感觉很混乱,经常理不清思路,感觉在上课期间也不在状态,从而在后面函数的练习中出现困难,希望后面自己能克服,改变现状。