본문 바로가기

[JavaScript] 자바스크립트 문자열로 변환해주는 함수 String()

액트 2022. 4. 20.
반응형

자바스크립트 문자열로 변환해주는 함수 String()


String()

String() 함수는 전달받은 객체의 값을 문자열로 변환하여 반환해 줍니다.

 

문법

String(객체);

예제

<!DOCTYPE html>
<html lang="ko">

<head>
	<meta charset="UTF-8">
	<title>JavaScript Predefined Function</title>
</head>

<body>

	<h1>String() 함수</h1>

	<script>
		document.write(String(123) + "<br>");
		document.write(String(123.456) + "<br>");
		document.write(String("123") + "<br>");
		document.write(String(new Date()) + "<br>");
		document.write(String(null) + "<br><br>");

		document.write(String(true) + "<br>");
		document.write(String(false) + "<br>");
		document.write(String(Boolean(1)) + "<br>");
		document.write(String(Boolean(0)));
	</script>
	
</body>

</html>

결과값

String() 함수

123
123.456
123
Wed Apr 20 2022 17:14:26 GMT+0900 (한국 표준시)
null

true
false
true
false

반응형

댓글