--- id: javascript-math title: "JavaScript Math" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["Math object", "Math.round", "Math.PI", "Math methods", "Math.pow", "Math.random"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "math", "numbers"] raw_sources: ["https://www.w3schools.com/js/js_math.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Math]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The JavaScript `Math` object provides mathematical constants (like `Math.PI`, `Math.E`) and methods (rounding, powers, roots, trig, min/max, random) that operate on numbers without needing to be instantiated. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`Math` is a static object** β€” it exposes constants and methods directly (e.g. `Math.PI`, `Math.round(x)`), not via instances. [S1] - **Rounding family** β€” `round` (nearest integer), `ceil` (up), `floor` (down), and `trunc` (integer part). [S1] - **`Math.sign(x)`** returns whether `x` is negative, null, or positive. [S1] - **Powers and roots** β€” `Math.pow(x, y)` is x to the power y; `Math.sqrt(x)` is the square root. [S1] - **`Math.abs(x)`** returns the absolute (positive) value. [S1] - **Trig** β€” `Math.sin(x)` / `Math.cos(x)` take an angle in radians (convert from degrees with `* Math.PI / 180`). [S1] - **`Math.min()` / `Math.max()`** find the lowest / highest value in a list of arguments. [S1] - **`Math.random()`** returns a random number between 0 (inclusive) and 1 (exclusive). [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Degrees β†’ radians** β€” multiply by `Math.PI / 180` before passing to `Math.sin`/`Math.cos`. [S1] - **Rounding choice** β€” pick `round`/`ceil`/`floor`/`trunc` per the rounding behavior you need. [S1] - **Min/max over a list** β€” call `Math.min(...)`/`Math.max(...)` with multiple numeric arguments. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **The Math Object** β€” The `Math` object allows you to perform mathematical tasks on numbers. Unlike other objects, the `Math` object has no constructor; it is static and its methods and properties are accessed directly. [S1] **Math Properties (constants)** β€” [S1] | Property | Description | |----------|-------------| | `Math.E` | Returns Euler's number | | `Math.PI` | Returns PI | | `Math.SQRT2` | Returns the square root of 2 | | `Math.SQRT1_2` | Returns the square root of 1/2 | | `Math.LN2` | Returns the natural logarithm of 2 | | `Math.LN10` | Returns the natural logarithm of 10 | | `Math.LOG2E` | Returns base 2 logarithm of E | | `Math.LOG10E` | Returns base 10 logarithm of E | **Math Methods** β€” selected methods documented on the page: [S1] | Method | Description | |--------|-------------| | `Math.round(x)` | Returns x rounded to its nearest integer | | `Math.ceil(x)` | Returns x rounded up to its nearest integer | | `Math.floor(x)` | Returns x rounded down to its nearest integer | | `Math.trunc(x)` | Returns the integer part of x | | `Math.sign(x)` | Returns if x is negative, null or positive | | `Math.pow(x, y)` | Returns the value of x to the power of y | | `Math.sqrt(x)` | Returns the square root of x | | `Math.abs(x)` | Returns the absolute (positive) value of x | | `Math.sin(x)` | Returns the sine of the angle x | | `Math.cos(x)` | Returns the cosine of the angle x | | `Math.min()` | Can be used to find the lowest value in a list | | `Math.max()` | Can be used to find the highest value in a list | | `Math.random()` | Returns a random number between 0 (inclusive), and 1 (exclusive) | | `Math.log(x)` | Returns the natural logarithm of x | | `Math.log2(x)` | Returns the base 2 logarithm of x | | `Math.log10(x)` | Returns the base 10 logarithm of x | **Example expressions and their results** β€” as shown on the page: [S1] | Expression | Result | |------------|--------| | `Math.round(4.6)` | 5 | | `Math.round(4.5)` | 4 | | `Math.round(4.4)` | 4 | | `Math.ceil(4.9)` | 5 | | `Math.floor(4.9)` | 4 | | `Math.trunc(4.9)` | 4 | | `Math.sign(-4)` | -1 | | `Math.pow(8, 2)` | 64 | | `Math.sqrt(64)` | 8 | | `Math.abs(-4.7)` | 4.7 | | `Math.sin(90 * Math.PI / 180)` | 1 | | `Math.cos(0 * Math.PI / 180)` | 1 | | `Math.min(0, 150, 30, 20, -8, -200)` | -200 | | `Math.max(0, 150, 30, 20, -8, -200)` | 150 | | `Math.random()` | A number between 0 (inclusive) and 1 (exclusive) | > Note: The full source presents these expressions inside interactive "Try it Yourself" Example boxes. The expressions and results above are reproduced from the page; any code that exists only inside the Try-it editor without a printed expression is "Not found in source". ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” rounding 4.x values, computing `Math.pow(8, 2)`, taking `Math.sqrt(64)`, converting degrees to radians for `Math.sin`/`Math.cos`, and finding min/max over a list. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Round to nearest / up / down / truncate: ```javascript Math.round(4.6); // 5 Math.ceil(4.9); // 5 Math.floor(4.9); // 4 Math.trunc(4.9); // 4 ``` Power, square root, absolute value: ```javascript Math.pow(8, 2); // 64 Math.sqrt(64); // 8 Math.abs(-4.7); // 4.7 ``` Degrees to radians for trig: ```javascript Math.sin(90 * Math.PI / 180); // 1 Math.cos(0 * Math.PI / 180); // 1 ``` Min / max over a list: ```javascript Math.min(0, 150, 30, 20, -8, -200); // -200 Math.max(0, 150, 30, 20, -8, -200); // 150 ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Random]], [[JavaScript Numbers]], [[JavaScript Array Sort]] - **μ°Έμ‘° λ§₯락:** Referenced whenever numeric computation, rounding, or randomness is needed. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Math β€” https://www.w3schools.com/js/js_math.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Math" page (Astra wiki-curation, P-Reinforce v3.1 format).