JS 문자열 결합 연산자 (+)
2021. 7. 15. 22:28
728x90

- 피연산자가 둘 다 숫자이면 산술 연산인 덧셈을 수행
- 피연산자가 하나라도 문자열이라면 문자열 결합을 수행

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>문자열 덧셈</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script>
//문자열 + 데이터 ---> 하나의 문자열로 합치는 기능
var str = "안녕하세요" + 100;
document.write(str, "<br>");
str = "안녕하세요" + false;
document.write(str, "<br>");
str = "안녕하세요" + 3.1415156;
document.write(str, "<br>");
str = "안녕하세요" + (300 + 400 + 500);
document.write(str, "<br>");
</script>
</head>
<body>
</body>
</html>
|
cs |
728x90
'JavaScript > Study' 카테고리의 다른 글
JS 논리 연산자 (&&, ||, !) (0) | 2021.07.15 |
---|---|
JS 비교 연산자 (동등 연산자, 일치 연산자, ==, ===, !=, !==, >, >=, <, <=) (0) | 2021.07.15 |
JS 대화상자 (prompt) (0) | 2021.07.15 |
[JS] 증감 연산자 (++x, x++, --x, x--) (0) | 2021.07.15 |
[JS] 대입 연산자 (=, +=, -=, *=, /=, %=) (0) | 2021.07.15 |