Blogger Information
Blog 18
fans 0
comment 0
visits 15813
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript 基础变量声明和函数
沉寂的博客
Original
593 people have browsed it

JavaScript 基础变量声明和函数

Js变量常量的声明及区别

  js变量ES6之前的版本用var声明,ES6之后用,let声明,列如:
let sum;,也可以声明和初始化一块做列如:let sum=20;,变量不可以重复定义,但是值可以更改。
  常量的声明和初始化要一起做,因为一旦常量定义之后是不可以在改变的,
列如:const NAME='商城APP';

函数和匿名函数的区别

函数一般是由function开头的有函数名称参数{}组成,而匿名函数是把函数赋值给一个变量,匿名函数可以没有函数名称,列如

  1. //匿名函数
  2. let sum = function (a,b){
  3. return a+b;
  4. };
  5. //函数
  6. function sum(a,b){
  7. return a+b;
  8. }
  9. //箭头函数是用来简写“匿名函数的”,列如:
  10. let sum = (a,b)=>{
  11. return a+b;
  12. };
  13. //如果匿名函数只有一天语句可以省掉大括号和return,如果只有一个参数,可以省掉小括号,
  14. //如果没有参数,小括号不能省略,列如:
  15. let sum=(a,b)=>a+b;
  16. let str=str=>console.log(str);
  17. let userName=()=>console.log('欢迎:'+ userName);

回调函数和纯函数

  回调函数是以函数作为参数,或者函数作为返回值的哈数叫做回调函数,纯函数就是有用function声明的有函数名有参数,并且以大括号结束的函数;

  1. //回调函数是以函数作为参数,或者函数作为返回值的哈数叫做回调函数
  2. function getDate() {
  3. return Date.now();
  4. }
  5. console.log(getDate());

纯函数执行结果:
纯函数执行结果

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!