Math.abs(-1) // 1
Math.abs('-1') // 1
Math.abs('') // 0
Math.abs([]) // 0
Math.abs(null) // 0
Math.abs(undefined) // NaN
Math.abs({}) // NaN
Math.abs('string') // NaN
Math.abs() // NaN
Math.abs([2]); // 2
Math.abs(['2']) // 2
Math.abs([1,2]); // NaN
Math.round(1.4) // 1
Math.round(1.6) // 2
Math.round(-1.4) // -1
Math.round(-1.6) // -2
Math.round(1) // 1
Math.round() // NaN
Math.round('') // 0
Math.round([]) // 0
Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095
Math.sqrt(1); // 1
Math.sqrt(0); // 0
Math.sqrt(-1); // NaN
Math.random() //0에서 1미만의 랜덤 실수
/*
1에서 10범위의 랜덤 정수 취득
1) Math.random으로 0에서 1미만의 랜덤 실수를 구한 다음, 10을 곱해서 0에서 10 미만의 랜덤 실수를 구한다.
2) 0에서 10미만의 랜덤 실수에 1을 더해 1에서 10 범위의 랜덤 실수를 구한다.
3) Math.floor로 1에서 10 범위의 랜덤 실수의 소수점 이하를 떼어 버린 다음 정수를 반환
*/
const random = Math.floor((Math.random()*10)+1)
console.log(random) // 1에서 10 범위의 정수
-두 값 사이의 난수 생성
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
-두 값 사이의 정수 난수 생성
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //최댓값은 제외, 최솟값은 포함
}
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/random
console.log(Math.pow(7, 3));
// expected output: 343
console.log(Math.pow(4, 0.5));
// expected output: 2
console.log(Math.pow(7, -2));
// expected output: 0.02040816326530612
// (1/49)
console.log(Math.pow(-7, 0.5));
// expected output: NaN
Math.pow(7, 2); // 49
Math.pow(7, 3); // 343
Math.pow(2, 10); // 1024
// 분수 지수
Math.pow(4, 0.5); // 2 (4의 제곱근)
Math.pow(8, 1/3); // 2 (8의 세제곱근)
Math.pow(2, 0.5); // 1.4142135623730951 (2의 제곱근)
Math.pow(2, 1/3); // 1.2599210498948732 (2의 세제곱근)
// 양의 지수
Math.pow(7, -2); // 0.02040816326530612 (1/49)
Math.pow(8, -1/3); // 0.5
// 양의 밑
Math.pow(-7, 2); // 49 (제곱의 결과값은 양수입니다.)
Math.pow(-7, 3); // -343 (세제곱은 음수가 될 수 있습니다.)
Math.pow(-7, 0.5); // NaN (음수는 실제 제곱근을 가지지 않습니다.)
// "짝수"와 "홀수" 근이 서로 가깝게 놓여 있고
// 부동소수점 정밀도의 한계로 인해,
// 밑이 음수이며 지수가 분수라면 언제나 NaN을 반환합니다.
Math.pow(-7, 1/3); // NaN
2**2 //4
console.log(Math.max(1, 3, 2));
// expected output: 3
console.log(Math.max(-1, -3, -2));
// expected output: -1
const array1 = [1, 3, 2];
console.log(Math.max(...array1));
// expected output: 3