Does an LLM have any idea of what "best" is?

I think it doesn't, and just predicts the range of most statistically likely next tokens based on its training data, and picks one of those.

In ML, "best" is what minimises the loss function, so in a certain (very basic) sense it does.