A unary function is a function that takes only one input value and returns a single output value. In other words, it has one parameter. The parameter name is usually written inside parentheses next to the function name. For example, if we have a function called addOne
, it takes an integer as its input parameter and returns the sum of 1 plus that integer as its output.
Here's an example:
function addOne(num):
return num + 1
console.log(addOne(5))
# Output: 6
In this example, the addOne
function takes a single integer parameter num
, which is then added to 1 (using the +
operator) and returned as the output. The input value passed to the function is 5
, and the output is 6
.