How TensorFlow will know if the prediction is true or false? I'm completely new at ML, but really interested. To be honest, read many articles about it, but still don't understand the workings of it.

I just started to understand this example: https://storage.googleapis.com/tfjs-examples/mnist/dist/index.html

My thinking about it is that TF has some resources, some examples of how numbers look like, and try to match them with the ones in the test. I saw that sometimes the test changes a right prediction to a wrong, but makes better and better predictions. But how? I think that the program doesn't know the right predictions (and this way it won't know the wrong ones). In the training how it makes better predictions? Test by test, from what exceptions it will change it's predictions? What happens in a new test?
During the training process, the machine learning program is shown example inputs (in this case pictures of digits) and also what the answer should be for that input. That is how it learns the correct answer.
However, it does not learn an exact mapping between the input data and required output, instead it learns a series of patterns that generally map the input to the required value. The advantage of this approach is that it can perform the same mapping on new inputs that were not included in the training data but are similar (but not necessarily identical) to examples that it has already seen.