innovationM
← Back to Blogs

Java Application

Unary function in javascript

InnovationM Admin 04 May 2023 2 min read
Unary function in javascript

A unary function is a mathematical function that takes only one argument or input. It is a function of a single variable, which means that it operates on a single operand. The term “unary” comes from the Latin word “unarius” meaning “consisting of one.”

For example, the function f(x) = x^2 is a unary function because it takes only one input, x, and returns the square of x. Another example of a unary function is the absolute value function f(x) = |x|, which returns the positive value of x regardless of its sign.

Unary functions are often used in computer programming, where they are used to transform or manipulate data. They can also be used in various fields of mathematics, including calculus, linear algebra, and logic.

Here’s an example of a unary function in mathematics:

f(x) = 2x

This function takes a single input x and returns the result of multiplying x by 2. For example, if we plug in x = 3, we get:

f(3) = 2(3) = 6

So, f(3) returns the value 6. This function is an example of a unary function because it has only one input variable (x) and operates on that single variable.

 

// Define a unary function that doubles its input

function double(x) {

  console.log( x * 2);

}

// Use the function to double a value

const num = 3;

const result = double(num); // result is now 6

About the Author

InnovationM Admin

Contributor at InnovationM.

LinkedIn

Transform Your Ideas with Expert Guidance

icon
15+ Years of Expertise

Delivering high-impact solutions with years of industry experience.

icon
100+ Satisfied Clients

Helping contact industry software experts to achieve their brand goals.

icon
250+ In-House Team Members

A skilled team ready to tackle projects of any scale.

Book a consultation call with our experts today