Search

_0012_문자열_백틱출력

대분류
STEP00 기초문법
소분류
기초문법_문자열

영상

개념

<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>문자열 출력</title> </head> <body> <script> /* [개념] 문자열 출력 (1) 백틱( ` )을 활용하면 문자를 보다 쉽게 출력할 수 있다. (2) ${} 를 사용해 변수를 사용할 수 있다. */ let x = 10; let y = 20; // 기존 방식 : 더하기 연산자로 변수와 문자를 연결 let rs1 = x + " + " + y + " = " + (x + y) + "<br>"; document.write(rs1); // 백틱(`) 방식 : ${변수} let rs2 = `${x} + ${y} = ${x + y}<br>`; document.write(rs2); </script> </body> </html>
Java
복사