首页 > 编程语言 >JavaScript 箭头函数

JavaScript 箭头函数

时间:2022-10-28 13:23:19浏览次数:36  
标签:return 函数 JavaScript 箭头 let 省略

箭头函数的形式:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //普通函数
      let sum = function () {};

      //箭头函数
      let sum2 = () => {};

      //当参数只有一个值的时候,可以省略小括号

      let num3 = (a) => {
        return a * a;
      };

      //当函数体只有一行代码,可以省略大括号
      //如果把大括号省略的话,会自动的返回结果,不要写return

      let fun = (a) => a * a;
      console.log(fun(6));
    </script>
  </body>
</html>

箭头函数的使用:

 

标签:return,函数,JavaScript,箭头,let,省略
From: https://www.cnblogs.com/ZhuAo/p/16835759.html

相关文章