간결한 화살표 함수 구문은 다음과 같습니다 -
(param1, param2) =>param1+param2
함수 키워드와 함수 본문이 없습니다. 매개변수와 함수 본문 사이에는 =>만 있고 단일 매개변수가 있는 경우 다음과 같이 작성할 수도 있습니다. -
param1=>param1*2
=> 뒤에 중괄호 {}가 없으면 암시적으로 반환됩니다.
다음은 JavaScript에서 간결한 화살표 기능을 구현하는 코드입니다 -
예시
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.result {
font-size: 20px;
font-weight: 500;
color: blueviolet;
}
</style>
</head>
<body>
<h1>Concise arrow functions</h1>
<div class="result"></div>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to call the add() concise arrow function</h3>
<script>
let resEle = document.querySelector(".result");
let add = (a, b) => a + b;
document.querySelector(".Btn").addEventListener("click", () => {
resEle.innerHTML = "Sum of 32 and 19 =" + add(32, 19);
});
</script>
</body>
</html> 출력

'여기를 클릭' 버튼을 클릭하면 -
