Why do dogs bark when a stranger is approaching?

Dogs are, by nature, both communitarian and territorial animals which consider their owners as the leaders of their respective packs.

When a stranger approaches, dogs bark: They are alerting the other members of their pack, the humans, that they should be aware of the presence of that stranger and decide what to do with him. It is their way to show their commitment to the rest of their pack.

Knowledge + Why?