A command is a backslash followed by letters, and it may take arguments in braces. \frac takes two — the numerator and the denominator — and stacks them. A command ends at the first non-letter, which is why \frac{a}{b} needs no space but \pi r does.
Step 4 of 17 of the LaTeX tutorial. The formula of the step, \frac{a+b}{c} = \frac{1}{2}, opens in a live playground you can edit.
Write a LaTeX or mhchem formula and see it drawn as you type, save it as an SVG that opens again, learn the notation step by step, and practise it with graded exercises. The tool needs JavaScript, because the formulas are drawn in your browser.