React Native
String literal(react native)
SallyJ
2022. 9. 29. 13:43
String literal 은 문자열과 변수를 편하게 다룰 수 있게 해주는 문법이다.
// String literal
const str1 = 'Hello';
const str2 = 'World';
const result = str1 + ' '+ str2 + '!!!';
console.log(result); // Hello World!!!
// `${variable}`
const litStr = `${str1} ${str2}!!!` // 키보드 숫자 1옆에 있는 기호 ~밑 작은 따옴표
console.log(litStr); // Hello World!!!
첫번째 방법과 두번째 방법 모두 같은 결과값이 나온다.
하지만 난 왠지 첫번째 방법이 편해서 첫번째 방법으로 계속 쓸 듯하다...