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

BELATED ARTICLES

more