< 자주 볼 메소드들 >
- Math.abs() : 절댓값 반환
- Math.ceil() : 소수점 올림(큰 정수 반환)
- Math.floor() : 소수점 내림(작은 정수 반환)
- Math.round() : 반올림한 가장 가까운 정수 반환
- Math.trunc() : 소숫점 버리고 정수 반환
Math.ceil(-7.004) // -7
Math.floor(-5.05) //-6
Math.round(-5.05) //-5
Math.round(-5.5) // -5
Math.trunc(-0.123) //-0
- Math.log() : base e , 0이상이면 -Infinity 반환, 음수면 NaN 반환
- Math.log10() : base 10 , 음수면 NaN 반환
- Math.log2 : base 2
Math.log10(100) //2
Math.log10(-2) // NaN
Math.log10(0) // -Infinity
Math.log2(8) // 3
Math.log2(1) // 0
Math.log2(0) // -Infinity
- Math.max() : 가장 큰 숫자 반환, 파라미터 없으면 -Infinity 반환
- Math.min() : 가장 작은 숫자 반환, 파라미터 없으면 Infinity 반환
Math.max(-1,-3,-2) // -1
const array1 = [1,3,2]
Math.max(...array1) // 3
- Math.pow(base, exponent) = base**exponent
- Math.sqrt() : 제곱근 반환, 음수면 NaN 반환 (square root of a number)
Math.pow(4,0.5) //2
Math.pow(7,-2) // 1/49
Math.pow(-7,0.5) //NaN
Math.sqrt(-1) //NaN
Math.sqrt(-0) // -0
Math.sqrt(9) //3
- Math.random() : 0이상 1미만의 부동소숫점 의사 난수 반환
- 암호학적으로 안전한 난수를 제공하지 않는다 => 보안과 관련된 어떤 것에도 사용 하면 안 된다
대신, Web Crypto API 의 window.crypto.getRandomValues() 메소드 이용- 대신, Web Cypto API의 window.crypto.subtle.generateKey() 사용
React Hook 중에 useId 사용- 리스트에서 키값 부여하기
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
https://react.dev/learn/rendering-lists#where-to-get-your-key
'FrontEnd > JavaScript' 카테고리의 다른 글
[ JavaScript ] super() (feat. 클래스) (0) | 2023.10.25 |
---|---|
[ JavaScript ] 단축 평가 short-circuit evaluation 논리 계산법 (0) | 2023.10.25 |
[ JavaScript ] require() vs import() (0) | 2023.10.25 |
[ JavaScript ] switch문에서 비교연산자 사용하기 (0) | 2023.10.25 |
[ JavaScript ] 소수점 올림, 내림, 반올림, 정수 반환, n번째 자리까지만 (feat Math.) (0) | 2023.10.25 |