게으른개발너D

[Built-in Objects] 까먹는 것 정리 본문

개발/JavaScript

[Built-in Objects] 까먹는 것 정리

lazyhysong 2023. 7. 12. 17:41

Built-in Objects (표준내장객체)


 

1. parseInt()

n진수를 10진수로 변환

(문자열 인자를 파싱하여 특정 진수의 정수를 반환)

const numStr = '101';

// 2진수 '101'을 10진수로 변환
const change1 = parseInt(numStr, 2);
console.log(change1);
// output:{number} 5

// 5진수 '101'을 10진수로 변환
const change2 = parseInt(numStr, 5);
console.log(change2);
// output:{number} 26

반대) Number.prototype.toString()

 

[Number] 까먹는 것 정리

Number Prototypes 1. Number.prototype.toString() 10진수를 n진수로 변환 const num = 5; // 5를 2진수로 변환 const change1 = num.toString(2); console.log(change1); // output:{string} "101" // 5를 4진수로 변환 const change2 = num.toString(4

lazyhysong.tistory.com

 

Comments