JS/시나리오 코드
함수 표현식
개발자공부
2024. 7. 19. 10:42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>index8.html 파일입니다.</h1>
<script>
// 1. 매개 변수가 없는 함수 표현식을 정의해 보자.
// let 보다 const가 메모리 성능이 조금 더 빠르다.
const currentTime = function(){
const now = new Date();
return now.toLocaleTimeString();
};
console.log(currentTime);
console.log(currentTime());
// 주의! 결과에 대한 분석을 통해 이해해 보자.
const time = currentTime();
console.log("-----------------");
console.log(time);
// 2.
const add = function(x,y){
return x + y;
}
console.log(add(3,5));
const result = add(10,20);
console.log(result);
</script>
</body>
</html>