Blogger Information
Blog 47
fans 0
comment 0
visits 21345
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数据类型与分支结构
P粉036614676
Original
327 people have browsed it

1.数据类型

1.基本数据类型

  • undefined
    • 没有赋值的对象
  • boolean
    • true和false
  • string
    • .length(和数组一样)
    • +(字符串合并)
    • string()函数
  • number
    • 8,10,16进制
    • 科学计数法
    • 值的范围:
      Number.MAX_VALUE , Number.MAX_VALUE ,Infinity
    • NAN:是不是数值(isNAN()函数)
    • parseInt(),parse(),第一个参数是要解析的数,第二个数是按多少进制转换(函数)
    • number(),undefined转换为NAN
  • object
  • symbol

2.引用类型

1.数组

  1. 定义数组

    1. let arr1 = new Array()
    2. let arr2 = new Array(2)
    3. let arr3 = new Array(10)
    4. let arr4 = []

    2.数组操作

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title></title>
    8. </head>
    9. <body>
    10. <script>
    11. // 栈操作
    12. let arr1 = new Array()
    13. for(i=0;i<3;i++)
    14. {
    15. arr1.push(i);//尾插入
    16. }
    17. m = arr1.pop()
    18. console.log(m);
    19. // 队列
    20. let arr2 = new Array(5)
    21. arr2.fill(1);
    22. for(i=0;i<5;i++)
    23. {
    24. arr2.unshift(i);//头插入
    25. }
    26. console.log(arr2);
    27. console.log(arr1.reverse());//逆向
    28. function compare(count1,count2)
    29. {
    30. if(count1<count2)
    31. {
    32. return true
    33. }
    34. else
    35. {
    36. return false
    37. }
    38. }
    39. console.log(arr2.sort(compare));//排序
    40. //1.把字符串变成数组
    41. let str = '12345'
    42. console.log(str.length);
    43. let str2 = Array.from(str)
    44. console.log(str2);
    45. //1.1把数组变成字符串
    46. let arrs = str2.join('')
    47. console.log(typeof arrs,arrs);
    48. // 2.对数组进行整体操作
    49. console.log(Array.from(str2,function (x){return x*x;}));
    50. // function (x){return x*x;等价于x=>x**x
    51. // 3.把一组参数转换为数组
    52. console.log(Array.of(1,2,3));
    53. let strr = [1,23,4,5,6]
    54. // 提取
    55. console.log(strr.slice(1,3));
    56. // splice:插入,删除等操作
    57. </script>
    58. </body>
    59. </html>

2.流程控制

  1. //分支
  2. let count = 10;
  3. // if语句
  4. if(count < 10)
  5. {
  6. console.log(count-1);
  7. }else if(count == 10){
  8. console.log(count);
  9. }else{
  10. console.log(count+1)
  11. }
  12. // =>count>10?console.log(10):console.log(1);;
  13. // while语句
  14. let x = 1
  15. do{
  16. console.log(x);
  17. x++;
  18. }while(x<2)
  19. // for语句
  20. for(;x<8;x+=2)
  21. {
  22. console.log(x);
  23. break;
  24. }
  25. // for in 语句
  26. arr = [1,2,3]
  27. for(i in arr)
  28. {
  29. print(i)
  30. }
  31. // break和continue
  32. for(let i =0 ;i<5;i++)
  33. {
  34. if(i%3==0)
  35. {
  36. continue;
  37. }
  38. console.log(i);
  39. }
  40. let y = 10;
  41. switch(y){
  42. case 1:
  43. console.log(1);
  44. break;
  45. case 2:
  46. case 3:
  47. // 满足2或者3输出1
  48. console.log(1);
  49. break;
  50. default:
  51. console.log(10);
  52. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post