Blogger Information
Blog 145
fans 7
comment 7
visits 164150
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS基础知识:Js的引入使用和变量声明
李东亚¹⁸⁰³⁹⁵⁴⁰¹²⁰
Original
909 people have browsed it

课堂知识总结:

1、JS相关属性:
src=""引用外部JS文件,且忽略内部JS代码;
defer:JS代码延后执行,在html文档加载完毕在执行JS代码;
asnyc:js代码和当前html文档解析同步进行;
2、变量:
var变量声明,=变量赋值初始化;(变量声明和初始化);
=变量更新;
3、与PHP对比:
(1).JS变量和PHP变量一样区分大小写;
(2).函数:在JS中区分大小写,在php中不区分大小写;
4、ES5和ES6中语法区别:
(1).JS在ES5中允许变量重新声明,不在存在块作用域
(2).JS在ES6中存在块作用域
(3).JS中函数内部可以直接使用外部变量;
5、JS中变量声明提升:变量未定义之前就可以使用了,但是值是:undefined;

代码练习:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>js练习</title>
  7. <!-- 引用外部js链接 -->
  8. <!-- <script src="JavaScript.js"></script> -->
  9. <!-- <script defer src="JavaScript.js"></script> -->
  10. <script async src="JavaScript.js"></script>
  11. </head>
  12. <body>
  13. <h3>Hello,欢迎来到JS世界!</h3>
  14. </body>
  15. <script>
  16. // 变量声明和初始化;变量声明关键字:var
  17. var name = "PHP";
  18. console.log(name);
  19. // 变量区分大小写
  20. name = "种业圈";
  21. console.log(name);
  22. NAME = "zhongyequan";
  23. console.log(NAME);
  24. //在ES5中变量重复声明
  25. var name = "PHP中文网";
  26. console.log(name);
  27. console.log("……………………………………");
  28. //函数区分大小写
  29. function A() {
  30. console.log("大写A函数内容");
  31. }
  32. function a() {
  33. console.log("小写a函数内容");
  34. }
  35. A();
  36. a();
  37. console.log("……………………………………");
  38. function write() {
  39. var site = "站点";
  40. console.log(name); //可以直接访问外部变量
  41. }
  42. write();
  43. // console.log(site);外部不能访问函数内变量
  44. console.log("……………………………………");
  45. //{}ES5不支持块作用域,但ES6支持
  46. {
  47. //块作用域
  48. var age = 30;
  49. console.log(name);
  50. }
  51. console.log(age);
  52. console.log(sex); //变量声明自动提升
  53. var sex = "男";
  54. console.log(sex);
  55. </script>
  56. </html>

运行结果图

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:以后的课程, 不再涉及ES6, 请将重点放在ES5上
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