What is a Unary Function in JavaScript?

A unary function is similar to the unary operator as the unary operator allows you to operate it with only one operand in a similar way a unary function allows you to pass only a single parameter to it. A unary function accepts only a single parameter and operates the different operations on it inside the function body. A unary function can be defined using any of the methods available in JavaScript to declare functions. The word unary means single or mono which means it can be operated with only one parameter.

Example: The below code example will explain the concept of the unary operator in JavaScript.

Javascript




function unaryFunc(param){
    console.log(param*33);
}
unaryFunc(5);
unaryFunc(3);


Output

165
99

Contact Us