--- id: javascript-arithmetic title: "JavaScript Arithmetic" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JS arithmetic", "arithmetic operators", "operator precedence", "modulus operator", "exponentiation operator", "increment decrement"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "arithmetic", "operators"] raw_sources: ["https://www.w3schools.com/js/js_arithmetic.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Arithmetic]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Arithmetic operators perform arithmetic on numbers (literals or variables), with multiplication and division taking higher precedence than addition and subtraction. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Arithmetic on numbers** β€” arithmetic operators perform arithmetic on numbers, which can be literals or variables. [S1] - **Operands and operators** β€” the numbers in an arithmetic operation are called operands; the operation performed between two operands is defined by an operator. [S1] - **Eight arithmetic operators** β€” `+`, `-`, `*`, `**`, `/`, `%`, `++`, `--`. [S1] - **Modulus returns the remainder** β€” the modulus operator `%` returns the division remainder. [S1] - **Exponentiation equals Math.pow** β€” `x ** y` produces the same result as `Math.pow(x, y)`. [S1] - **Precedence and left-to-right** β€” multiplication and division have higher precedence than addition and subtraction; operations of equal precedence are computed left to right; parentheses override precedence. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Operate over literals or variables** β€” the operands of an arithmetic expression can be literals (`100 + 50`), variables (`a + b`), or sub-expressions (`(100 + 50) * a`). [S1] - **Increment/decrement in place** β€” `x++` raises and `x--` lowers a variable by one. [S1] - **Force evaluation order with parentheses** β€” wrap a lower-precedence operation in `()` to make it run first. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **JavaScript Arithmetic Operators** [S1] Arithmetic operators perform arithmetic on numbers (literals or variables): | Operator | Description | |----------|-------------| | + | Addition | | - | Subtraction | | * | Multiplication | | ** | Exponentiation (ES2016) | | / | Division | | % | Modulus (Remainder) | | ++ | Increment | | -- | Decrement | **Arithmetic Operations** [S1] A typical arithmetic operation operates on two numbers. The two numbers can be literals: ```javascript let x = 100 + 50; ``` or variables: ```javascript let x = a + b; ``` or expressions: ```javascript let x = (100 + 50) * a; ``` **Operators and Operands** [S1] The numbers (in an arithmetic operation) are called operands. The operation (to be performed between the two operands) is defined by an operator. **Adding** [S1] ```javascript let x = 5; let y = 2; let z = x + y; ``` **Subtracting** [S1] ```javascript let x = 5; let y = 2; let z = x - y; ``` **Multiplying** [S1] ```javascript let x = 5; let y = 2; let z = x * y; ``` **Dividing** [S1] ```javascript let x = 5; let y = 2; let z = x / y; ``` **Remainder** [S1] The modulus operator (`%`) returns the division remainder. The result of a modulo operation is the remainder of an arithmetic division. ```javascript let x = 5; let y = 2; let z = x % y; ``` **Incrementing** [S1] The increment operator (`++`) increments numbers. ```javascript let x = 5; x++; let z = x; ``` **Decrementing** [S1] The decrement operator (`--`) decrements numbers. ```javascript let x = 5; x--; let z = x; ``` **Exponentiation** [S1] The exponentiation operator (`**`) raises the first operand to the power of the second operand. ```javascript let x = 5; let z = x ** 2; ``` `x ** y` produces the same result as `Math.pow(x, y)`: ```javascript let x = 5; let z = Math.pow(x,2); ``` **Operator Precedence** [S1] Operator precedence describes the order in which operations are performed in an arithmetic expression. Multiplication and division have higher precedence than addition and subtraction: ```javascript let x = 100 + 50 * 3; ``` Parentheses can change the order β€” operations inside parentheses are computed first: ```javascript let x = (100 + 50) * 3; ``` When many operations have the same precedence (like addition and subtraction or multiplication and division), they are computed from left to right: ```javascript let x = 100 + 50 - 3; ``` ```javascript let x = 100 / 50 * 3; ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” adding/subtracting/multiplying/dividing into `z`, taking a remainder with `%`, incrementing/decrementing, exponentiating with `**` vs `Math.pow`, and demonstrating precedence with and without parentheses. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Operate over two variables: ```javascript let x = 5; let y = 2; let z = x % y; ``` Exponentiate (two equivalent forms): ```javascript let z = x ** 2; let z = Math.pow(x,2); ``` Override precedence with parentheses: ```javascript let x = (100 + 50) * 3; ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. The source notes the exponentiation operator `**` was introduced in ES2016, which is the relevant version context. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Operators]], [[JavaScript Assignment]], [[JavaScript Types]], [[JavaScript Comparisons]] - **μ°Έμ‘° λ§₯락:** Referenced whenever computing numeric values or reasoning about evaluation order in expressions. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Arithmetic β€” https://www.w3schools.com/js/js_arithmetic.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Arithmetic" page (Astra wiki-curation, P-Reinforce v3.1 format).