Last Updated : 23 Jul, 2025
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:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4