The weighted average is a method of calculating the cost of inventory by considering the varying costs of units purchased at different times. It is a technique used in both perpetual and periodic inventory systems to determine the cost of goods sold and the value of ending inventory.