728x90

✨ 문자열로 바꾸고싶을 때, toString() 대신에 사용하는 new String();
(e.g., const numToStr = new String(num)) 왼쪽처럼 선언하여 Number를 String으로 사용한다.

💻Example Code

const num = 77;
const numToStr = new String(num);

console.log( num );
console.log( numToStr );
console.log( numToStr.split('') ); // 활용 예시

실행 결과(Number 77, String 77, split된 77)

😋 [String: '77']의 정확한 의미는 모르겠지만, 일반 String처럼 사용 가능하다. 아마 Object가 생성되는 것 같다.
(조금 더 학습할 필요성이 있다)

👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

 

String

The String global object is a constructor for strings or a sequence of characters.

developer.mozilla.org

 

'JavaScript > Built-in Method etc.' 카테고리의 다른 글

String.prototype.match()  (0) 2019.12.31
String.charCodeAt()  (0) 2019.12.31
new Array()  (0) 2019.12.29
Array.prototype.메소드() 만들기  (0) 2019.12.29
Array.prototype.fill()  (0) 2019.12.29

+ Recent posts