백틱(``)

Heewon👩🏻‍💻·2024년 4월 25일

JS코드

const loginForm = document.querySelector("#login-form");
const loginInput = loginForm.querySelector("input");
const greeting = document.querySelector("#greeting");

const HIDDEN_CLASS = "hidden";
function onLoginFormSubmit(event) {
  event.preventDefault();
  const userName = loginInput.value;
  loginForm.classList.add(HIDDEN_CLASS);
  console.log(userName);
  greeting.innerText = `Hello ${userName}`;
  greeting.classList.remove(HIDDEN_CLASS);
}

loginForm.addEventListener("submit", onLoginFormSubmit);

백틱 안에서는 String 과 변수명을 동시에 사용할 수있다.

`Hello ${변수명}` == "Hello " + 변수명
profile
Interested in coding, meat lover, in love with dogs , enjoying everything happens in my life.

0개의 댓글