Assignment operator (=)
The = operator stores an expression's value in a variable or object property and returns the assigned value. It neither compares values nor declares variables.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
The = operator stores an expression's value in a variable or object property and returns the assigned value. It neither compares values nor declares variables.
An await expression suspends the current execution of an async function or module until the awaited value settles. It produces a promise’s fulfillment value or throws its rejection reason without blocking the entire thread.
The & operator keeps bits set to 1 in both operands. It is used for masking and testing flags; for Number it operates on signed 32-bit integers, while BigInt results are not limited to 32 bits.
The &= operator computes the bitwise AND of the target’s current value and the right operand, then stores the result in that same target. It is useful for retaining only bits selected by a mask. It supports Number and BigInt, but not a mixture of them.
The unary ~ operator flips the bits of a numeric value. For Number it operates on a signed 32-bit integer; for BigInt it does not restrict the value to 32 bits. It must not be confused with logical NOT (!).
The | operator combines the bits of two values: a result bit is 1 when at least one corresponding operand bit is 1. It supports Number and BigInt, but does not allow mixing those types.
The |= operator performs bitwise OR on the target's current value and the right operand, then performs an assignment of the computed result to the target. It can set the bits selected by a mask without clearing the others and supports Number and BigInt.
The ^ operator performs bitwise exclusive OR: a result bit is 1 when the corresponding operand bits differ. It supports Number and BigInt, but does not allow those numeric types to be mixed.
The ^= operator computes the bitwise exclusive OR of the target’s current value and the right operand, then assigns the result to that target. It can toggle bits using a mask and supports Number and BigInt, but does not allow mixing those types.
The comma operator evaluates expressions from left to right and returns the last value. Side effects from earlier expressions are preserved. Do not confuse it with commas separating arguments, array elements, or declarations.
The conditional operator `?:` selects one of two values based on a condition. It is an expression: it evaluates the condition and then only the selected branch, whose value becomes the result.
The -- operator subtracts one and writes the result back to its operand. The x-- form returns the previous numeric value, while --x returns the new value. Both support Number and BigInt.
The delete operator removes an object's own property, not the object itself or a variable. Learn its Boolean result, strict-mode restrictions, and the holes it leaves in arrays.
The / operator computes the quotient of two operands. Number division can return a fraction, while BigInt division discards the fractional part toward zero. Mixing these types and dividing a BigInt by zero throw exceptions.
The /= operator divides the current value of a variable or property by the right operand and stores the result in the same location. It supports Number and BigInt, but does not allow those types to be mixed.
The == operator compares values using specified conversion rules when operand types differ. Learn how it differs from ===, how null and undefined are treated, and why objects are compared by identity.
The ** operator raises a base to a given power. Learn its right associativity, the syntax rules for negative bases, and the differences between Number and BigInt calculations.
The **= operator raises a target's current value to a specified power and stores the result in the same location. The target is evaluated only once. It supports Number and BigInt, but does not allow mixing those types.
The >= operator checks whether the left operand is greater than or equal to the right operand. Comparison can convert types, so strings, null, and NaN deserve particular attention.
The > operator checks whether the left operand is greater than the right operand. It returns a Boolean but may first convert its operands. Two strings are compared lexicographically rather than numerically.
The `in` operator checks for a property by key, not by value. For an ordinary object with an ordinary prototype chain, it checks for both own and inherited properties. A `Proxy`'s `has` trap can change the result. The right operand must be an object; a primitive causes `TypeError`.
The ++ operator adds one to a numeric value and attempts to write the result back to its operand. The count++ form returns the previous numeric value, while ++count returns the new value.
The != operator tests inequality using comparison rules that allow implicit type conversion. It negates ==, so values of different types do not necessarily produce true. The !== operator does not perform these conversions.
With an ordinary, unbound function on the right, the instanceof operator defaults to checking whether the function’s `prototype` occurs in an object’s prototype chain. It accounts for inheritance, but does not prove how an object was created or that particular fields exist.