Blogger Information
Blog 37
fans 0
comment 0
visits 14260
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript (常量、变量、函数)使用
秋闲独醉
Original
287 people have browsed it
  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>javascript基础</title>
  8. </head>
  9. <body>
  10. <!-- javascript代码可以被包含在<script></script>标签内,也可以包含在.js结尾的文件中 -->
  11. <!-- 第一种 -->
  12. <script>
  13. // js代码
  14. </script>
  15. <!-- 第二种 -->
  16. <!-- <script src="javascript.js"></script> -->
  17. <!-- javascript 变量的声名和定义 -->
  18. <script>
  19. // 变量名命名:必须只能有字母、数字、下划线、$,四种组合在一起;
  20. // 必须只能是字母、$、下划线开头。
  21. // 一般用小写字母。
  22. let a = "123";
  23. let a_ = "123";
  24. let _a = "123";
  25. let $_a = "123";
  26. let $_a1 = "123";
  27. // 以var 定义 的变量是全局变量,以let 定义的变里视作用域决定,可全局可局部
  28. {
  29. var b = "88";
  30. }
  31. {
  32. let c = "77";
  33. }
  34. console.log(b);
  35. // console.log(c); //这个报错,因为c是局部变量,不能在全局使用。
  36. // + 符号的使用,可以用作两个字符串之间的连接
  37. console.log("我是" + "一个好人");
  38. //常量的声名和赋值,都用同时,这个于变量不一样。
  39. //常量名通常是大写字母加下划线
  40. APP_NAME = "这是一个APP";
  41. console.log(APP_NAME);
  42. APP_NAME = "这不是一个APP";
  43. console.log(APP_NAME);
  44. //函数名通常用小驼峰命名
  45. let name = "佚名";
  46. function setUserName(param) {
  47. name = param;
  48. }
  49. setUserName("小丸子");
  50. console.log(name);
  51. //匿名函数
  52. let getUserName = function (username) {
  53. return "HELLO " + username;
  54. };
  55. console.log(getUserName("小不点"));
  56. let getUserName2 = (username) => {
  57. return "hello" + username;
  58. };
  59. console.log(getUserName2("小物件"));
  60. </script>
  61. </body>
  62. </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