Swords are used to fight enemies in Forager, and they function in a lot the same ways as the Pickaxe; swing it towards an enemy to damage it. You won't start the game with any Sword though, so here's how to unlock Sword in Forager.
Firstly you will need to unlock the skill called "Combat". The "Combat" skill is located directly two blocks to the right of the "Magic" Skill (that is one of the four Skills you start with). Just like any other skill in the game, you need to spend a Skill Point to unlock it, and once you do, you have it permanently.
After you get the Combat skill, you also get the Sword automatically in your Tool kit, so you don't even need to craft it. You should upgrade it though, and the first upgrade called "Bone Sword" can be done at the Forge for 16x Iron Ingots, 8x Bricks and 4x Bones. You can keep upgrading it to make it deal more damage and give it special features.
Since the Sword is a tool, it won't take up an inventory slot, and you will have permanent access to it after you get it.
Most people don't really prefer playing with the Sword, since the Pickaxe and Bow tend to do about the same amount of damage, so why bother with the sword at all?