Front-end/Vanilla JS

javascript 문자열 이어붙이기

1924 2021. 12. 5. 20:12

문자열 + 문자열

문자열.concat("문자열")

 

"문자열" + 3.14를 하게 되면

숫자가 문자열로 변환되어 "문자열 3.14" 문자열로 나옵니다.

 

 

var str = "hello";
str + " asd"

'hello asd' // 결과값

var str = "hello";
str.concat(" World")

'hello World' // 결과값

var str = "hello";
str.concat(" World").concat("!!")

'hello World!!' // 결과값

var str = "hello";
str.concat(" World").concat("!!").concat(123)

'hello World!!123' // 결과값