Question: I'm going to make a validation of a string, using javascript `isNaN` build in function. But depending of other variable, I want to negate de value of the `isNaN`, so I can check if its a Number or Not a Number

*e.g.:* 

I'm trying to do something like this, but in javascript, it's not valid

```
function validation(objectWithStrings, type){
    let stringCheck = type == 1 ? isNaN : !isNaN
    ...
}

```

I want to make this so I don't need to make a lot of `if` / `else` statements in the middle of my code, I can't just call `stringCheck(someString)` and get if it's `true` or `false`.

Is there a way to get the function in a variable but when you call it, it return the result of the function negated? 

**Observation:** I don't want a better way to check if a string is a number or not, I want to get a way of returning the negated value of any function.

Answer: 
The expression `isNaN` is valid javascript function but `!isNaN` is not. You need to pass a valid javascript function that returns the opposite of `isNaN`:

```
function validation(objectWithStrings, type){
    const stringCheck = type == 1 ? isNaN : (str) => !isNaN(str)
    ...
}

```
Taking into account the observation, you can create a `negate` function that accepts a callback and negates the result of callback execution:

```js
const isNumber = value => !isNaN(+value);
const negate = fn => (...args) => !fn(...args);

const isNotNumber = negate(isNumber);

console.log(isNumber('10'));
console.log(isNotNumber('10'));
```