CLASS web

JavaScript

형변환 - 데이터를 문자열로 변환하기 String

형변환 - 데이터를 문자열로 변환하기 String

이번시간에도 앞의 강좌에 이어 형변환에 대해서 알아보겠습니다.

이번에는 문자열 데이터로 형변환하는 방법에 대해 알아보겠습니다.

어떠한 데이터를 문자열로 변경하려면 String()

어떠한 데이터를 문자열로 변경하려면 String()를 사용합니다.

String(변수)

String()은 string형으로 데이터를 변환합니다.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>pinkcoding - JavaScript - type conversion</title>
<script>
    var num = 440;
    document.write(num + ' of type is ' + typeof(num) + '<br>');
    str = String(num); //date type conversion
    document.write(str + ' of type is ' + typeof(str));
</script>
</head>
<body>
</body>
</html>

결과는 바로 아래에서 확인할 수 있습니다.







JavaScript type conversion

숫자 440이 문자열 440으로 변경되었습니다.





댓글 0개

정렬기준

PinkCoding

PinkCoding

X

PinkCoding

Web Scratch Pad

X

loading

            
            
        

컨텐츠로 돌아가기