const number = 12345;
const test = number.toString();
console.log(typeof test);
// type = string
- toString์ ์ซ์ํ์
์ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝํด์ค๋ค.
- ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ง๊ณ ๋ ํ๊ฐ์ง์ ์ฌ์ฉ๋ฒ์ด ๋ ์๋๋ฐ ๋ฐ๋ก ์ซ์๋ฅผ ์ํ๋ ์ง๋ฒ์ผ๋ก ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํ๋ค.
const number = 12;
const test = number.toString(2);
console.log(typeof test, test);
// console.log(string 1100);
- ํ์
์ ๋์ผํ๊ฒ string์ผ๋ก ๋ณ๊ฒฝ๋๋ฉฐ ํด๋น ์ซ์๋ฅผ 2์ง๋ฒ์ผ๋ก ๋ณ๊ฒฝํด์ value๋ฅผ ๋ฑ๋๋ค.
- ๋งค๊ฐ๋ณ์(radix) ๋ ์ ํ์ฌํญ์ด๋ฉฐ ์ง๋ฒ์ ๋ณํ๊ฐ ํ์ํ ๋์ ํ์ํ์ง ์์๋๋ฅผ ๊ตฌ๋ถํ์ฌ ์ฌ์ฉํ๋ฉด ๋ ๊ฑฐ๊ฐ๋ค๐