프레임워크/React Native

React에서 string 안에 ${변수} 사용

pythaac 2021. 7. 12. 12:28

  이런... string 안에서 ${변수}를 사용하려면 '가 아니라 `를 사용해야한다. 세미콜론(;)급 통수다 ㅠㅠ

 ' 

  • Single Quote
  • 세미콜론의 오른쪽에 있은
  • " (Double Qutoe)와 함께 string을 표현할 때 사용

 ` 

  • Backtick
  • 1의 왼쪽, ESC 아래, ~와 함께 있음
  • ${변수}를 인식 : string templating에 사용

 

이전에는 string의 concatenating을 사용해야하냐, templating을 사용해야하냐를 논했지만, 현재는 비슷하다고 판단하는듯 하다. concatenation이 빠르다는 말도, templating이 빠르다는 말도 있다.

 

참고 내용

[1] https://hello-bryan.tistory.com/120

 

React `string 안에 ${변수명}` 잘 안될 때

React Variables and String Variables in String format 처음 시작할 때 잘 모를수도 있는 내용이라 적어봅니다. 아래와 같은 코드가 있습니다. render() { const {username} = this.state; return ( mysql conne..

hello-bryan.tistory.com

[2] https://stackoverflow.com/questions/47067319/back-tick-vs-single-quote-in-js

 

Back-tick vs single quote in js

Working on node.js (server side), I wonder if I should use all back-ticks (`) instead of the regular quotes (" or ') all the time since it will make the code consistent. Is there any specific reaso...

stackoverflow.com

[3] https://stackoverflow.com/questions/29055518/are-es6-template-literals-faster-than-string-concatenation

 

Are ES6 template literals faster than string concatenation?

Does HTML code generation run measurably faster in modern browsers when using string concatenation or template literals in ES6? For example: String concatenation ""+ "<

stackoverflow.com