void Operator

The void operator evaluates the given expression and then returns undefined.

Syntax:

void expression
void( expression )

Example: In this example, we are using the void operator.

Javascript




function myFunction() {
    return void 0;
}
console.log(myFunction());


Output

undefined


JavaScript Unary Operators

JavaScript Unary Operators work on a single operand and perform various operations, like incrementing/decrementing, evaluating data type, negation of a value, etc.

Table of Content

  • Unary Plus (+) Operator
  • Unary Minus (-) Operator
  • Unary Increment (++) Operator
  • Unary Decrement (–) Operator
  • Logical NOT (!) Operator
  • Bitwise NOT (~) Operator
  • typeof Operator
  • delete Operator
  • void Operator

We will explore all the above operators along with their basic implementation with the help of examples.

Similar Reads

Unary Plus (+) Operator

The unary plus (+) converts an operand into a number, if possible. It is commonly used to ensure numerical operations on variables that may contain numeric strings. If the operand is a string that represents a valid number, it will be converted to a number. Otherwise, it will evaluate to NaN (Not-a-Number)....

Unary Minus (-) Operator

...

Unary Increment (++) Operator

The Unary Negation (-) operator is used to convert its operand to a negative number if it isn’t already a negative number....

Unary Decrement (–) Operator

...

Logical NOT (!) Operator

The unary increment operator (++) adds 1 to its operand’s value and evaluates to the updated value. It can be used as a postfix or prefix operator....

Bitwise NOT (~) Operator

...

typeof Operator

The unary decrement operator (–) subtracts 1 from its operand’s value and evaluates it to the updated value, and we can use it as a postfix or prefix operator....

delete Operator

...

void Operator

The logical NOT (!) is a unary operator that negates the Boolean value of an operand, converting true to false and false to true....