[30 Days of JS] Create Hello World Function / Counter
2025. 5. 7. 07:37ㆍ개인활동/코테
반응형
/**
* @return {Function}
*/
var createHelloWorld = function() {
return function(...args) {
return "Hello World";
}
};
/**
* const f = createHelloWorld();
* f(); // "Hello World"
*/
- ...args : 들어오는 arguments를 무시하고 작업
- JSDoc : 데이터 타입, 함수, 함수의 파라미터 설명 등을 위한 주석
Documentation Comments in JSDoc - GeeksforGeeks
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
www.geeksforgeeks.org
/**
* @param {number} n
* @return {Function} counter
*/
var createCounter = function(n) {
return function() {
return n++;
};
};
/**
* const counter = createCounter(10)
* counter() // 10
* counter() // 11
* counter() // 12
*/
반응형
'개인활동 > 코테' 카테고리의 다른 글
[30 Days of JS] Apply Transform Over Each Element in Array / Filter Elements from Array (0) | 2025.05.09 |
---|---|
[30 Days of JS] To be or Not to be / Counter II (1) | 2025.05.08 |
[LeetCode/MySQL50] 577. Employee Bonus (0) | 2025.03.10 |
[LeetCode/MySQL50] 1661. Average Time of Process per Machine (0) | 2025.02.03 |
[LeetCode/MySQL50] 197. Rising Temperature (1) | 2025.01.28 |