The first instinct for most new knitters is to knot strands of yarn in their work.
Unfortunately, knots can be bulky and can show through from the back of knitting. They also can come undone quite easily, often ruining a treasured garment. The best solution to handle loose yarn ends is to weave them into the wrong side of the knitting.
Weaving in works best with animal fibers (wool, alpaca, silk) and not as well with plant based fibers (cotton, linen, hemp, rayon) which cannot felt and therefore won’t cling to itself as well.
With a darning needle, weave the ends of the yarn in and out through several rows in one direction, then repeat in the opposite direction. This will hold a loose yarn end more securely than the tightest knot!
On medium and finer weight fabrics weaving may be done on a diagonal to avoid a linear “echo” of the yarn on the front of the work. I find in most cases, though, this isn’t necessary.