Anderson was born at White Marsh, near Philadelphia, Pennsylvania, the son of William Anderson and Elizabeth Inslee. In 1776, following the outbreak of the American Revolutionary War, he enlisted in the 3rd New Jersey Regiment of the Continental Army, and rose to the rank of captain and paymaster in less than two years. Anderson fought at the Battle of Monmouth, and was with the army during its difficult 1777 wintering at Valley Forge. In 1781, he transferred to the 1st New Jersey Regiment, and fought with this unit at the Battle of Yorktown.