JavaScript Unary Operators

Subject: JavaScript

JavaScript unary operators perform operations on a single operand. These operators are used for actions like type conversion, negation, incrementing, and checking a variable’s type.


Common Unary Operators in JavaScript

  • + (Unary Plus)
  • - (Unary Minus)
  • ++ (Increment)
  • -- (Decrement)
  • typeof
  • delete
  • void

Example 1: Unary Plus and Minus

  • + converts the string or boolean to a number
  • - negates the number

Example 2: Increment and Decrement


Example 3: typeof Operator


Example 4: delete Operator

Removes a property from an object.


Example 5: void Operator

Always returns undefined, no matter the expression.


Key Takeaways

  • Unary operators act on one operand.
  • + and - are used for type coercion.
  • ++ and -- increase or decrease values.
  • typeof checks data type.
  • delete removes a property from an object.
  • void returns undefined — used in advanced scenarios like bookmarking or JS URIs.

Unary operators are useful for type conversion, logical control, and runtime debugging.

Next : String Operators