How a TOTP code is made
A TOTP code (RFC 6238) is a one-time password computed from two things: the secret key a service gave you when you turned on two-factor authentication, and the current time. The time step changes every 30 seconds, and so does the code. The service computes the same code on its side and compares the two.
Your secret stays on this device
The code is computed with the Web Crypto API built into your browser. The page sends nothing: not the secret, not the code, not the account name. Nothing is stored and the secret is never put in the address bar, so a reload or a closed tab forgets it.
When to use it, and when not
It helps when your authenticator app is on a phone you do not have with you, or to check that a secret you wrote down is right. Anyone who holds a secret can make its codes, so keep it as private as a password, and for everyday use add it to an authenticator app on a device you trust.
Your account depends on a phone number too?
Many services tie sign-in and recovery to a phone number as well. Take a private number that is yours alone and is not given to anyone else while you keep it.