From UBC Wiki

On the justified true belief theory of knowledge, a proposition P counts as knowledge for some person X if and only if:

1. P is justified

2. P is true

3. the person X believes that P

A belief can be justified but false (see justifying reasons entry for an example). In such cases, the belief does not count as knowledge.

A belief can be unjustified but true. For example, despite my having no good evidence for the name of a stranger sitting next to me on the bus, I may come to believe that his name is Bob simply because I fancy the name (and I have occasionally irrational criteria for forming beliefs). However, thanks to some stroke of luck, his name is indeed Bob. My belief is true, but unjustified - I didn't form the belief based on any evidence.