剰余代入演算子 (%=) - JavaScript
原題: Remainder assignment (%=) - JavaScript - RealityRipple
分析結果
- カテゴリ
- AI
- 重要度
- 54
- トレンドスコア
- 18
- 要約
- 剰余代入演算子 (%=) は、変数を右側の値で割った余りをその変数に代入する演算子です。この演算子を使用することで、コードを簡潔にし、計算を効率的に行うことができます。具体的な構文や例、ブラウザの互換性についても説明されています。
- キーワード
Remainder assignment (%=) - JavaScript Skip to main content Syntax Examples Specifications Browser compatibility See also Related topics The remainder assignment operator ( %= ) divides a variable by the value of the right operand and assigns the remainder to the variable. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request. Syntax Operator: x %= y Meaning: x = x % y Examples Using remainder assignment // Assuming the following variable // bar = 5 bar %= 2 // 1 bar %= 'foo' // NaN bar %= 0 // NaN Specifications Specification ECMAScript (ECMA-262) The definition of 'Assignment operators' in that specification. Browser compatibility The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. Desktop Mobile Server Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js Remainder assignment ( x %= y ) Chrome Full support 1 Edge Full support 12 Firefox Full support 1 IE Full support 3 Opera Full support 3 Safari Full support 1 WebView Android Full support 1 Chrome Android Full support 18 Firefox Android Full support 4 Opera Android Full support 10.1 Safari iOS Full support 1 Samsung Internet Android Full support 1.0 nodejs Full support 0.1.100 Legend Full support Full support See also Assignment operators in the JS guide Remainder operator Related Topics JavaScript Tutorials: Complete beginners JavaScript basics JavaScript first steps JavaScript building blocks Introducing JavaScript objects JavaScript Guide Introduction Grammar and types Control flow and error handling Loops and iteration Functions Expressions and operators Numbers and dates Text formatting Regular expressions Indexed collections Keyed collections Working with objects Details of the object model Using promises Iterators and generators Meta programming JavaScript modules Intermediate Client-side JavaScript frameworks Client-side web APIs A re-introduction to JavaScript JavaScript data structures Equality comparisons and sameness Closures Advanced Inheritance and the prototype chain Strict mode JavaScript typed arrays Memory Management Concurrency model and Event Loop References: Built-in objects AggregateError Array ArrayBuffer AsyncFunction Atomics BigInt BigInt64Array BigUint64Array Boolean DataView Date Error EvalError FinalizationRegistry Float32Array Float64Array Function Generator GeneratorFunction Infinity Int16Array Int32Array Int8Array InternalError Intl JSON Map Math NaN Number Object Promise Proxy RangeError ReferenceError Reflect RegExp Set SharedArrayBuffer String Symbol SyntaxError TypeError TypedArray URIError Uint16Array Uint32Array Uint8Array Uint8ClampedArray WeakMap WeakRef WeakSet WebAssembly decodeURI() decodeURIComponent() encodeURI() encodeURIComponent() escape() eval() globalThis isFinite() isNaN() null parseFloat() parseInt() undefined unescape() uneval() Expressions & operators Addition (+) Addition assignment (+=) Assignment (=) Bitwise AND (&) Bitwise AND assignment (&=) Bitwise NOT (~) Bitwise OR (|) Bitwise OR assignment (|=) Bitwise XOR (^) Bitwise XOR assignment (^=) Comma operator (,) Conditional (ternary) operator Decrement (--) Destructuring assignment Division (/) Division assignment (/=) Equality (==) Exponentiation (**) Exponentiation assignment (**=) Function expression Greater than (>) Greater than or equal (>=) Grouping operator ( ) Increment (++) Inequality (!=) Left shift (<<) Left shift assignment (<<=) Less than (<) Less than or equal (<=) Logical AND (&&) Logical AND assignment (&&=) Logical NOT (!) Logical OR (||) Logical OR assignment (||=) Logical nullish assignment (??=) Multiplication (*) Multiplication assignment (*=) Nullish coalescing operator (??) Object initializer Operator precedence Optional chaining (?.) Pipeline operator (|>) Property accessors Remainder (%) Remainder assignment (%=) Right shift (>>) Right shift assignment (>>=) Spread syntax (...) Strict equality (===) Strict inequality (!==) Subtraction (-) Subtraction assignment (-=) Unary negation (-) Unary plus (+) Unsigned right shift (>>>) Unsigned right shift assignment (>>>=) async function expression await class expression delete operator function* expression in operator instanceof new operator new.target super this typeof void operator yield yield* Statements & declarations async function block break class const continue debugger do...while empty export for for await...of for...in for...of function declaration function* if...else import import.meta label let return switch throw try...catch var while with Functions Arrow function expressions Default parameters Method definitions Rest parameters The arguments object getter setter Classes Private class fields Public class fields constructor extends static Errors Error: Permission denied to access property "x" InternalError: too much recursion RangeError: argument is not a valid code point RangeError: invalid array length RangeError: invalid date RangeError: precision is out of range RangeError: radix must be an integer RangeError: repeat count must be less than infinity RangeError: repeat count must be non-negative ReferenceError: "x" is not defined ReferenceError: assignment to undeclared variable "x" ReferenceError: can't access lexical declaration "x" before initialization ReferenceError: deprecated caller or arguments usage ReferenceError: invalid assignment left-hand side ReferenceError: reference to undefined property "x" SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated SyntaxError: "use strict" not allowed in function with non-simple parameters SyntaxError: "x" is a reserved identifier SyntaxError: JSON.parse: bad parsing SyntaxError: Malformed formal parameter SyntaxError: Unexpected token SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead SyntaxError: a declaration in the head of a for-of loop can't have an initializer SyntaxError: applying the "delete" operator to an unqualified name is deprecated SyntaxError: for-in loop head declarations may not have initializers SyntaxError: function statement requires a name SyntaxError: identifier starts immediately after numeric literal SyntaxError: illegal character SyntaxError: invalid regular expression flag "x" SyntaxError: missing ) after argument list SyntaxError: missing ) after condition SyntaxError: missing : after property id SyntaxError: missing ; before statement SyntaxError: missing = in const declaration SyntaxError: missing ] after element list SyntaxError: missing formal parameter SyntaxError: missing name after . operator SyntaxError: missing variable name SyntaxError: missing } after function body SyntaxError: missing } after property list SyntaxError: redeclaration of formal parameter "x" SyntaxError: return not in function SyntaxError: test for equality (==) mistyped as assignment (=)? SyntaxError: unterminated string literal TypeError: "x" has no properties TypeError: "x" is (not) "y" TypeError: "x" is not a constructor TypeError: "x" is not a function TypeError: "x" is not a non-null object TypeError: "x" is read-only TypeError: "x" is not iterable TypeError: More arguments needed TypeError: Reduce of empty array with no initial value TypeError: X.prototype.y called on incompatible type TypeError: can't access dead object TypeError: can't access property "x" of "y" TypeError: can't assign to property "x" on "y": not an object TypeError: can't define property "x": "obj" is not extensible TypeError: can't delete non-configurable array element TypeError: can't redefine non-configurable property "x" TypeError: cannot use "in" operator to search for "x" in "y" TypeError: cyclic object value TypeError: invalid "instanceof" operand "x" TypeError: invalid Array.prototype.sort argument TypeError: invalid arguments TypeError: invalid assignment to const "x" TypeError: property "x" is non-configurable and can't be deleted TypeError: setting getter-only property "x" TypeError: variable "x" redeclares argument URIError: malformed URI sequence Warning: -file- is being assigned a //# sourceMappingURL, but already has one Warning: 08/09 is not a legal ECMA-262 octal constant Warning: Date.prototype.toLocaleFormat is deprecated Warning: JavaScript 1.6's for-each-in loops are deprecated Warning: String.x is deprecated; use String.prototype.x instead Warning: expression closures are deprecated Warning: unreachable code after return statement Misc JavaScript technologies overview Lexical grammar JavaScript data structures Enumerability and ownership of properties Iteration protocols Strict mode Transitioning to strict mode Template literals Deprecated features