카테고리 없음

JS 템플렛 문자열 백틱 (TAB위에 있는 )

Canyi 2022. 11. 8. 14:32

결과는 똑같으나 사용법이 다름

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
</head>
<body>
    <script>
        const name = "마이클";
        const age = 25;
        const height = 180.5;

        // console.log("My Name is " + name +", " + "My age is " + age
        //             + ", " + "My height is " + height);
        
        console.log(`My Name is  ${name}, 
My age is ${age}, 
My height is ${height}`);

    </script>
</body>
</html>

 

그냥 문자열 출력

console.log("My Name is " + name + ", "  + "My age is " + age + ", " + "My height is " + height);

 

 

백틱 사용(`)

console.log(`My Name is  ${name}, 
             My age is ${age}, 
             My height is ${height}`);