이 글은 Let's Get IT 자바스크립트 프로그래밍이라는 책의 예제를 따라하며 자습하는 글입니다.
<script>
const number = Number(prompt('몇 명이 참가하나요?'));
const $button = document.querySelector('button');
const $input = document.querySelector('input');
const $word = document.querySelector('#word');
let word;
let newWord;
const onClickButton = () => {
if (!word) {
word = newWord;
$word.textContent = word;
} else {
}
};
const onInput = (event) => {
newWord = event.target.value;
};
$button.addEventListener('click', onClickButton);
$input.addEventListener('input', onInput);
</script>
... 저번과 같은 예제를 보고 있는 것 같으나, 공부할 부분이 좀 있어 같이 봐야만 했다.
특별한 목적의 작업을 수행하도록 설계된 독립적인 블록
function 함수명 (매개변수, 매개변수, ...) {
실행문;
반환문; (옵션)
}
function showMessage() {
alert('안녕하세요!');
}
일반적인 함수 선언 방식
funtion sayHi() {
console.log('Hi!');
}
sayHi();
익명 함수를 값으로써 변수에 할당한 것
let sayHello = function () {
console.log('Hello!');
}
function
키워드 대신 화살표(=>)를 사용하여 간략하게 선언하는 방법
위의 예제에선 화살표함수로 표현함
예시
let sayHello = () => {
console.log('Hi!');
}
https://bigtop.tistory.com/40
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Functions/Arrow_functions
https://poiemaweb.com/es6-arrow-function
https://whales.tistory.com/37