GeeksforGeeks App
Open App
Browser
Continue

# How to test a value x against predicate function and returns fn(x) or x in JavaScript ?

In this article, we are given a value x, and the task is to check the value against the predicate function. If the value satisfies the condition or predicate return fn(x) else return x.

Predicate functions are the function that takes one item as input and returns true or false based on the whether item satisfies that condition or not.

Example 1: In this example, we have given a number and a condition, if condition is true then it returns the fn(number) otherwise it returns a simple numeric value.

## Javascript

 ``

Output: Here the condition is a number that should be even because our input data is even so it returns the fn(6) value.

`This function returns 720`

Example 2: In this example, we have given a number and a test condition, if condition is true then it returns the fn(number) otherwise it returns number value only.

## Javascript

 ``

Output:

`The function returns 610`

Example 3: In this example, we have given a number and a test condition, if condition is true then it returns the fn(number) otherwise it returns number value only.

## Javascript

 ``

Output:

`This function returns 7776`

My Personal Notes arrow_drop_up
Related Tutorials