This Javascript function is used to generate check digits. The last digit of some barcodes is a computer check digit which makes sure the barcode is correctly composed. Unfortunately Javascript does not play nicely with long Integers. This algorithm expects a String as input and does not handle Integers as input.
SSCC, GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN
Read more about manually calculating a check digit here.