Difference between getelementsbyname and getelementbyid

The difference between getElementsByName and getElementById
GetElementsByName gets an array
getElementById gets a number

function sum(n, m) {
            var summary = 0;
            var a = document.getElementsByName(n.toString());
            for (var i = 0; i < a.length; i++) {
                summary = summary + Number(a[i].value);
            }
            
            //1
            var b = document.getElementById(m);
            b.value = summary;
            //2
            var f = document.getElementsByName(m);
            f[0].value = summary;
        }

Read More: