What's the use of fence?

Fences will restrict the spread of grass and the movement of animals, so they're primarily useful for making pastures. That said, there's not really any harm in having your animals roam the whole farm except for making it slightly hard to find them. Other than that, there's no concrete gameplay benefit, but partitioning your farm into areas can make it more aesthetically pleasing and can help you with keeping tabs on different parts of your farm.

Since fences are just impassable tiles, they have no special effect when making a closed circle; they won't stop wood, stones, and grass from appearing inside a fenced off area, and they won't stop tilled soil from turning back into normal ground. There is technically nothing special about a fence that's not shared with other unpassable tiles.