react笔记之箭头函数1

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>箭头函数</title>
<script>
/*
* 箭头函数
* - 只有一个参数的函数
* 参数 => 返回值
* - 如果没有参数,或多个参数,参数需要使用()括起来
* () => 返回值
* (a, b, c) => 返回值
* - 箭头后边的值就是函数的返回值
* - 返回值必须是一个表达式(有值的语句)
* - 如果返回值是对象,必须加()
* - 如果需要在箭头函数中定义逻辑,可以直接在箭头后跟一个代码块,
* 代码块中语法和普通函数没有区别
* */
const fn = function (a){
return 'hello';
};
const fn2 = a => a+'hello';
const fn3 = (a, b) => a+'hello';
// console.log(fn2(123));
const sum = (a, b) => a + b;
let result = sum(123, 456);
const fn4 = (a, b) => {
if(a === 10){
a += 5;
}else if(a === 20){
a += 10;
}
return a + b;
};
result = fn4(10, 5);
console.log(result);
</script>
</head>
<body>
</body>
</html>

posted @   前端导师歌谣  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示