Blogger Information
Blog 46
fans 2
comment 0
visits 19627
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js实例演示变量
P粉314265155
Original
339 people have browsed it

js基础

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>js演示</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 声明变量 a,且初始化赋值
  12. let a =10;
  13. let b =20;
  14. console.log( a);
  15. console.log(b);
  16. // 匿名函数
  17. {
  18. a + b ;
  19. let c =1;
  20. c = a + b ;
  21. console.log(c);
  22. console.log(typeof(a + b ));
  23. let d = '朱老师' ;
  24. console.log( d);
  25. console.log( typeof (d));
  26. console.log(typeof(d +c));
  27. }
  28. // console.log(c); 块的 作用域原因不能访问
  29. // {
  30. // // 在js中, 字符串的拼装: "+",二边至少有一个字符串
  31. // let s = 'Hello ' + 'World';
  32. // console.log(s);
  33. // console.log('a=', a, ', b=', b);
  34. // console.log(a + b);
  35. // console.log(a + '10');
  36. // console.log(typeof (a + '10'));
  37. // }
  38. // 命名函数
  39. function sum ( a,b ){
  40. return a + b ;
  41. }
  42. console.log(sum(10 , ',朱老师' ));
  43. console.log(sum(1, 2 ));
  44. function sum (j , k ) {
  45. let e = j+ k ;
  46. return e ;
  47. }
  48. console.log(sum (11, 20));
  49. // 全局作用域
  50. let email = '123@qq.com';
  51. {
  52. console.log(email);
  53. }
  54. let email2 = '456@qq.com' ;
  55. {
  56. let email2 = ' 789@qq.com';
  57. console.log(email2);
  58. }
  59. console.log(email2);
  60. // 我是常量
  61. const H = 66 ;
  62. console.log(H);
  63. //变量 命名法
  64. // 1、驼峰 大驼峰 UserName 小驼峰 userName 动词+名词
  65. // 2、蛇形 user_name
  66. //常量 命名法
  67. // USERNAME
  68. // 命名函数
  69. function getName(userName){
  70. return 'hello,' +userName ;
  71. }
  72. console.log( getName('朱老师'));
  73. // 匿名函数
  74. let getName1 = function (userName1){
  75. return 'hello' + userName1 ;
  76. }
  77. console.log(getName1('灭绝老师'));
  78. // let getUserName = function (username) {
  79. // return 'Hello, ' + username;
  80. // };
  81. // console.log(getUserName('马老师'));
  82. // console.log(getUserName('牛老师'));
  83. // console.log(getUserName('羊老师'));
  84. // console.log(lhusername)(
  85. // function (lhusername) {
  86. // return 'hello,' + lhusername ;
  87. // }
  88. // );
  89. // 阅读及焚
  90. console.log(
  91. (function (qjusername) {
  92. return 'Hello, ' + qjusername;
  93. })('灭绝老师')
  94. ) ;
  95. // 简化匿名函数
  96. // 去掉 function 及形参的括弧,在形参的右侧增加 => 胖箭头
  97. getName1 = userName1 => {
  98. return 'hello,' + userName1 ;
  99. }
  100. console.log(getName1('go老师'));
  101. // 再次简化 ,去掉{ } ,去掉return 注意又有分号
  102. getName1 = userName1 =>
  103. 'hello,' + userName1 ;
  104. console.log(getName1('猫老师'));
  105. let f = x => x * 2 ;
  106. console.log(f (3));
  107. f =(x ,z) => 5*7 ;
  108. console.log(f());
  109. f =(x ,z) => x+ z ;
  110. console.log(f(4,9));
  111. f =() => 'hello ,桌面花纹'
  112. console.log(f());
  113. </script>
  114. </body>
  115. </html>

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