이렇게 하면 코드를 읽기 쉽게 쓸 수 있고, 결과 문자열도 원하는 형태로 만들어집니다. 문자열
병합을 사용할 때는 따옴표와 백틱을 섞어 써도 괜찮습니다.
const
multiline
= '
Current
temperature
:\
n
' +
`\
t
${
currentTemp
}\
u00b0C
\
n
` +
"
Don
'
t
worry
...
the
heat
is
on
!";
3.8.3
숫자와 문자열
숫자를 따옴표 안에 넣으면 그건 숫자가 아니라 문자열입니다. 그렇긴 하지만, 자바스크립트는
필요하다면 숫자가 들어 있는 문자열을 자동으로 숫자로 바꿉니다. 이런 일이 언제 일어나는
지, 어떻게 일어나는지를 알지 못하면 혼란스러울 수 있습니다. 여기에 관해서는
5
장에서 다시
설명합니다. 다음 예제에 문자열을 숫자로 바꾸는 경우와 숫자로 바꾸지 않는 경우를 묘사했습
니다.
const
result1
=
3
+ '
30
'; //
3
이 문자열로 바뀝니다. 결과는 문자열 '
330
'입니다.
const
result2
=
3
* '
30
'; // '
30
'이 숫자로 바뀝니다. 결과는 숫자
90
입니다.
숫자가 필요할 땐 숫자를 쓰십시오(즉, 따옴표를 쓰지 마십시오). 문자열이 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.