5가지 방법이 있습니다. 값 변환 문자열로 . 그들은
-
빈 문자열 연결
-
템플릿 문자열
-
JSON. 문자열화
-
toString()
-
문자열()
예시
다음 예에서는 위에서 언급한 모든 방법을 사용하여 값을 문자열로 변환했으며 최종 결과는 출력과 같이 표시되었습니다.
<html>
<body>
<script>
const value = 123;
document.write((value + '') +" "+typeof (value + ''));
document.write("</br>");
document.write((`${value}`) +" "+typeof (`${value}`));
document.write("</br>");
document.write((JSON.stringify(value)) +" "+typeof (JSON.stringify(value)));
document.write("</br>");
document.write((value.toString()) +" "+typeof (value.toString()));
document.write("</br>");
document.write((String(value)) +" "+typeof(String(value)));
</script>
</body>
</html> 출력
123 string 123 string 123 string 123 string 123 string