Unary Operators
In this lesson, we meet the unary operators in JavaScript. Let's begin!
Operators
Every programming language needs expressions to describe calculations, algorithms, and even more complex concepts. Most languages use unary, binary, and sometimes ternary operators as basic building blocks of expressions.
It is the same for JavaScript, it uses operators to manipulate data values.
If you have already used curly-brace languages such as C, C++, Java, or C#, you will find the JavaScript operators familiar.
However, you must be more considerate with JavaScript operators, for the loosely-typed nature of the language delivers a few surprising things.
Unary operators
JavaScript supports the unary plus (+
), unary minus (–
), increment (++
), and decrement (––
) operators. The last two can be used either as prefix or postfix operators. In most programming languages, you can apply these operators only on numeric types, but JavaScript is more flexible.
Get hands-on with 1400+ tech skills courses.