The trigger.new provides the records that are about to be inserted, or updated. Likewise trigger.old returns the value of records before update or delete. Rest is simple code to update the values of the new records. You’ll see on thing in this code, that an update command or insert command is missing. This is because the trigger is already a part of the DML process and hence we do not need to call another DML command, or else there are chances of having and trigger recursion. So it is always a good habit to avoid DML for the same object in a trigger.