문자와 변수를 구분하여 추출할 때 유용한 기능이다.
var name = '홍길동';
function 해체분석기(문자들,변수들) {
console.log('문자들 > ', 문자들);
console.log('변수들 > ', 변수들);
}
해체분석기`안녕하세요. 제 이름은 ${name} 입니다`;
함수를 실행시킬 때 소괄호가 아니라 ` (백틱) 문자를 붙이면 된다.
첫번째 파라미터는 `백틱` 내의 순수 문자만 골라서 Array 로 만들어 놓은 파라미터
두번째 파라미터는 `백틱` 내의 ${} 변수를 담는 파라미터이다.
'JavaScript' 카테고리의 다른 글
[JavaScript/ES6] 함수의 default 파라미터 / 함수의 arguments / Rest 파라미터 (0) | 2024.08.26 |
---|---|
[JavaScript/ES6] Spread Operator (... 연산자) / apply, call 함수 (0) | 2024.08.26 |
[JavaScript/ES6] var, let, const / hoising, 전역변수, 참조 (0) | 2024.08.26 |
[JavaScript/ES6] Arrow function (0) | 2024.08.26 |
[JavaScript/ES6] this 총 정리 (0) | 2024.08.19 |