一、基础概念与定义方式
- 函数声明
javascriptCopy Code
function add(a, b) { return a + b; } // 存在函数提升:ml-citation{ref="1,6" data="citationList"}
- 函数表达式
javascriptCopy Code
const multiply = function(a, b) { return a * b; }; // 无提升,可匿名:ml-citation{ref="1,9" data="citationList"}
- 箭头函数
javascriptCopy Code
const square = x => x * x; // 无自己的this,适合简洁操作:ml-citation{ref="1,6" data="citationList"}
- 构造函数
javascriptCopy Code
const func = new Function('a', 'b', 'return a + b'); // 动态创建:ml-citation{ref="9" data="citationList"}
二、核心特性
-
参数处理
- 支持默认参数、剩余参数(