How a function is even and odd?

The only way a function can be both even and odd is for it to ignore the input, i.e. for it to be a constant function. e.g. f(x)=4 is both even and odd.

An even function is one where f(x)=f(-x), and an odd one is where -f(x)=f(-x).

This doesn't make sense. Let's analyze.

For a function to be even, f(-x)=f(x). For a function to be odd, f(-x)=-f(x).

In this case, f(x)=4, and f(-x)=4. As such, for the first part of the even-odd definition, we have 4=4, which is true, making the function even. However, for the second part of it, we have 4=-4 (f(-x)=4, but -f(x)=-4), which is not true. Therefore constant functions are even because f(-x)=f(x), but not odd because f(-x)!=-f(x).