백틱&특수문자

ssamu·2023년 7월 8일
0

1. 콘솔창에 문자열 여러줄을 출력하려면 백틱을 사용하장

쌍따옴표:

console.log("\\    /\\
 )  ( ')
(  /  )
 \\(__)|")

결과:
Uncaught SyntaxError: Invalid or unexpected token

백틱:

console.log(`\\    /\\
 )  ( ')
(  /  )
 \\(__)|`)

결과:

\    /\
 )  ( ')
(  /  )
 \(__)|

2. 특수문자앞에는 \를 붙이자

안 붙인경우:

console.log(`|\_/|
|q p|   /}
( 0 )"""\
|"^"`    |
||_/=\\__|`)

결과: Uncaught SyntaxError: Unexpected token '||'

붙인경우:

console.log(`|\\_/|
|q p|   /}
( 0 )"""\\
|"^"\`    |
||_/=\\\\__|`)

결과:

|\_/|
|q p|   /}
( 0 )"""\
|"^"`    |
||_/=\\__|

0개의 댓글