Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

JavaScript Arithmetic Unary Negation(-) Operator

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Unary negation(-) operation is a single operand operator (which means it worked with only a single operand preceding or succeeding to it), which is used to convert its operand to a negative number, if it isn’t already a negative number.

Syntax:

-Operand

Example 1: This example shows the use of JavaScript Unary negation(-) Operator.

Javascript




<script>
    const a = 20;
    const b = -a;
      
    console.log(b);
    console.log(typeof b);
      
    const x = '20';
    const y = -x;
      
    console.log(y);
    console.log(typeof y);
</script>

Output:

-20
number
-20
number

Example 2: This example shows the use of JavaScript Unary negation(-) Operator while working with numbers.

Javascript




<script>
    const x = 30;
    const y = -x;
      
    console.log(y);
    console.log(typeof y);
</script>

Output:

-30
number

Example 3: This example shows the use of JavaScript Unary negation(-) Operator working with non-numbers.

Javascript




<script>
    const x = "30";
    const y = -x;
      
    console.log(y);
    console.log(typeof y);
</script>

Output:

-30
number

We have a complete list of Javascript Operators, to check those please go through the Javascript Operators Complete Reference article.

Supported Browser:

  • Chrome
  • Edge
  • Firefox
  • Safari
  • IE
  • Opera

My Personal Notes arrow_drop_up
Last Updated : 06 Mar, 2023
Like Article
Save Article
Similar Reads
Related Tutorials