For the API user its not really important. But under the hood: It will do an insert if the record cannot be looked up and an update if it can.
Its a bit more complicated than that as you can work with multiple relations at the same time (inserting/updating multiple related records), but for each record it basically works as described above.