λ¬Έμ λ₯Ό νλ€λ³΄λ Math.~μΌλ‘ μμνλ λ©μλλ₯Ό μ¬μ©ν μΌμ΄ λ§λ€.
λ무 μ μ©νκ² μ¬μ©μ€μ΄λΌ μ 리ν΄λ³΄λ μμ£Ό μ¬μ©νλ Math κ°μ²΄ μ’ λ₯
Math λ©μλ
- Math.abs() : μ λ¬ λ°μ κ°μ μ λκ°μ λ°ννλ€.
let num1 = 4
let num2 = -4
Math.abs(num1); // 4
Math.abs(num2); // 4
Math.abs(num2 - num1); // 8
- Math.min() : μ λ¬ λ°μ κ°λ€ μ€ κ°μ₯ μμ κ°μ λ°ννλ€.
let num1 = 2;
let num2 = 4;
let num3 = 8;
Math.min(num1, num2, num3); // 2
- Math.max() : μ λ¬ λ°μ κ°μ μ€ κ°μ₯ ν° κ°μ λ°ννλ€.
let num1 = 2;
let num2 = 4;
let num3 = 8;
Math.max(num1, num2, num3); // 8
- Math.random() : 0κ³Ό 1 μ¬μ΄μ λμλ₯Ό λ°ννλ€.
Math.random(); // μ€νν λλ§λ€ κ°μ΄ λ¬λΌμ§λ€.
- Math.pow() : μ λ¬ λ°μ κ°μ nμ κ³±μ λ°ννλ€.
Math.pow(4, 2); // 16
Math.pow(5, 4); // 625
- Math.sqrt() : μ λ¬ λ°μ κ°μ μ κ³±κ·Όμ λ°ννλ€.
Math.sqrt(16); // 4
- Math.cbrt() : μ λ¬ λ°μ κ°μ μΈμ κ³±κ·Όμ λ°ννλ€.
Math.cbrt(8); // 2
- Math.ceil() : μ λ¬ λ°μ κ°λ³΄λ€ ν¬κ±°λ κ°μ μ μ€ κ°μ₯ μμ μ μλ₯Ό λ°ννλ€. (μ¬λ¦Ό)
Math.ceil(4.8); // 5
Math.ceil(8.4); // 9
- Math.round() : μ λ¬ λ°μ κ°μ λ°μ¬λ¦Όν μμ κ°μ₯ κ°κΉμ΄ μ μλ₯Ό λ°ννλ€. (λ°μ¬λ¦Ό)
Math.round(4.8); // 5
Math.round(8.4); // 8
- Math.floor() : μ λ¬ λ°μ κ°λ³΄λ€ μκ±°λ κ°μ μ μ€ κ°μ₯ ν° μ μλ₯Ό λ°ννλ€. (λ΄λ¦Ό)
Math.floor(4.8); // 4
Math.floor(8.4); // 8
'π Study > JavaScript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[JS] ν΄λμ€μ μΈμ€ν΄μ€ (0) | 2022.09.21 |
---|---|
[JS] μμ μλ£νκ³Ό μ°Έμ‘° μλ£ν (0) | 2022.09.21 |
[JS] νμ (0) | 2022.09.21 |
[JS] JavaScript Koans (0) | 2022.09.08 |
[JS] letκ³Ό constμ μ°¨μ΄μ (0) | 2022.08.22 |