For a nonnegative random variable $$E[X]=\int_0^\infty P(X >x)dx$$
This video on a question from IIT JAM 2023 extends it to $$E[X^2]=\int_0^\infty 2x P(X >x)dx$$
How was the result was arrived at? Where can I get references for such results? Books or structured references (rather than single links preferred).