Open In App

What is a Unary Function in JavaScript?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads