기본 매개변수 문법

ex)

function greet(name = "Guest") {
  console.log(`Hello, ${name}!`);
}

greet();        // "Hello, Guest!"
greet("Anna");  // "Hello, Anna!"

위 코드의 매개변수 name = “Guest” 와 같이 기본 매개변수를 지정해주면 함수를 호출할때 매개변수를 넣어주지 않으면 기본 매개변수로 실행되고, 매개변수를 입력해 주었을때는 입력된 매개변수로 실행시켜준다.

때문에 인자의 유무가 선택적인 함수에서 유용하게 사용할 수 있다.

This line appears after every note.

Notes mentioning this note


Here are all the notes in this garden, along with their links, visualized as a graph.