Expectation of $Y$ when $X,Y$ are jointly distributed. Suppose $X,Y$ are jointly distributed continuous random variables with probability density function $f_{X,Y}(x,y)$. I know that in order to recover the marginal distribution of one of the random variables, say $Y$, we can compute $$f_{Y}(y) = \int_{-\infty}^{\infty} f_{X,Y}(x,y) \, dx .$$
My question is about computing $E[Y]$ when starting from the above situation. Considering the fact that the definition of the expectation is $$E[Y] := \int_{-\infty}^{\infty} y \cdot f_{Y}(y) \, dy, $$
My approach is then to compute the expectation as $$E[Y] = \int_{-\infty}^{\infty} y \cdot f_Y(y) \, dy = \int_{-\infty}^{\infty} y \left[ \int_{\infty}^{\infty} f_{X,Y}(x,y) \, dx \,\right] dy = \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} y \cdot f_{X,Y}(x,y) \, dx \, dy. $$
However, I regularly see solutions that will compute it as $$E[Y] = \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} y \cdot f_{X,Y}(x,y) \, dy \, dx. $$
I am familiar with the concept of changing the order of integration, but this seems like more than that. It is no longer clear to me why this still fits the definition of the expected value, because I don't see how we are recovering the marginal pdf of $Y$ and then integrating it against $y$ to arrive at the expectation. I have asked several friends who also solved problems this way why it is valid and none of them seem to have an answer and they just say "why wouldn't you be able to calculate it this way?". So either I am crazy or they are unconscious statisticians. 

On that note, I did notice on a formula page in a text book it has an identity:
$$E[g(X,Y)] = \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} g(x,y) \cdot f_{X,Y}(x,y) \, dy \, dx.$$
In the above I agree the order of integration wont matter (by setting X = Y and vice versa). I suppose in this result if you take the function $g(X,Y) = Y$ it will permit the computation that I am hesitant about. Is this how we know we can do that? Or is it simpler than that and I am just being crazy?

As a concrete example, here is a specific problem where the solution provided uses the method I am hesitant about. 
Let $X$ and $Y$ denote the values of two stocks at the end of a five-year period. $X$ is uniformly distributed on the interval $(0,12)$. Given $X = x$, $Y$ is uniformly distributed on the interval $(0,x)$. Find $E[Y]$.
Please remember, my question is not how to solve this problem. It is why a specific method works.
My method of solving this would be to first discover that the support of $(X,Y)$ is $0 < y < x < 12$. Then since $f_{Y|X}(y|x) = x^{-1}$ and $f_{X}(x) = 12^{-1}$ we can deduce that $f_{X,Y}(x,y) = (12x)^{-1}$. Then compute 
$$f_{Y}(y) = \int_{y}^{12} (12x)^{-1} \, dx = (1/12)[\ln(12) - \ln(y)].$$
Then use this to compute 
$$E[Y] = \int_{-\infty}^{\infty} y \cdot f_{Y}(y) \, dy = \int_{0}^{12} y \cdot (1/12)[\ln(12) - \ln(y)] \, dy = 3.$$ 
Computing the last integral was... 'do-able' for a well-practiced integrater, but it was not ideal. 
The solution posted was the following:
$$E[Y] = \int_{0}^{12} \int_{0}^{x} (y/12x) \, dy \, dx = 3.$$
The above integral is much easier to solve, so once I understand this is a valid way to compute the expectation I will happily add this to my tool belt for solving problems. But again, I don't see how it fits the definition of expectation, because I don't see how it is recovering the marginal distribution for $Y$. Unless, doing it this way is using the identity that I mention in the middle block of text. 

So why is the other method valid?

 A: Assuming that $\mathbb E[|Y|]<\infty$ and $\int_{-\infty}^\infty |f_{X,Y}(x,y)|\ \mathsf dx<\infty$, by Fubini's theorem the integral
$$
\iint_{\mathbb R^2} yf_{X,Y}(x,y)\ \mathsf dm(x\times y)
$$
exists, and is equal to the integrated integrals
$$
\int_{-\infty}^\infty\int_{-\infty}^\infty y f_{X,Y}(x,y)\ \mathsf dx\ \mathsf dy
$$
and
$$
\int_{-\infty}^\infty\int_{-\infty}^\infty y f_{X,Y}(x,y)\ \mathsf dy\ \mathsf dx.
$$
A: It's a general fact that
 $$\int_{-\infty}^{\infty} \int_{-\infty}^{\infty}g(x,y)\ dx\ dy=\int_{-\infty}^{\infty} \int_{-\infty}^{\infty}g(x,y)\ dy\ dx,$$
provided that the integral exists. In particular this applies to $g(x,y)=yf_{X,Y}(x,y)$, as in your question.
Now you may ask why it is true, in which case I can either quote a theorem from a more advanced subject (this is what the other answer does) or I can explain why it has to be true, intuitively.
Think of the integrand $g(x,y)$ as a height function. In other words, we can think of a hill whose height above the point $(x,y)$ is $g(x,y)$. Then there are two ways of finding the volume of the hill: first you can subdivide into thin strips in the $x$ direction, and add up the volumes along each of those thin strips - or you can subdivide in the $y$ direction. Either way, you will get the same answer in the end, since the volume of the hill does not care which way we chop up the hill to calculate it. That's why the two integrals are the same.
