Blogger Information
Blog 7
fans 0
comment 0
visits 3925
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php学习0707
Lank的博客
Original
523 people have browsed it

1. 变量,常量,数据类型,实例演示,注意命名规范;

js的变量和常量,变量可更新,可先声明再赋值,常量不可更新,声明时必须初始化,变量声明用let,常量声明用const

  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. // 传统的变量方式,已淘汰或不建议使用
  13. // var email = "a@qq.com";
  14. // document.write(email);
  15. // alert(email);
  16. // var email = "555@qq.com";
  17. // console.log(email);
  18. // console.info(email);
  19. // 传统js,es6之前的js没有常量,靠自觉靠约定
  20. // var APP_NAME = "在线商城";
  21. // var APP_NAME = "我的小程序";
  22. // console.log(APP_NAME);
  23. let email = "222@qq.com";
  24. // let email = "333@qq.com";
  25. console.log(email);
  26. // 常量不能被更新,声明时必须初始化
  27. const NATION = "China";
  28. console.log(NATION);
  29. </script>
  30. </body>
  31. </html>
效果图如下

js的数据类型包括原始类型和引用类型

1、原始类型包括
数值:整数,小数
字符串:使用双引或者单引号
undefined:未定义
null:空
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= , initial-scale=1.0" />
  7. <title>数据类型</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 1.原始
  12. // 2.引用
  13. function hello() {}
  14. console.log(typeof hello);
  15. console.dir(hello);
  16. </script>
  17. </body>
  18. </html>

效果如下

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>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. function aa() {
  12. return 3 + 4;
  13. }
  14. console.log(aa());
  15. function bb(a, b) {
  16. return a + b;
  17. }
  18. console.log(bb(4, 4));
  19. // 匿名函数
  20. let nimi = function () {
  21. return 5 + 4;
  22. };
  23. console.log(nimi());
  24. // 匿名函数改造为箭头函数
  25. let nimi1 = () => 5 + 4;
  26. console.log(nimi1());
  27. </script>
  28. </body>
  29. </html>

运行效果如下

Correcting teacher:天蓬老师天蓬老师

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!