Spot the bug - #32

This text cleanup has one bug.

function normalizeTag(tag) {
  return tag.trim().toLowercase();
}

console.log(normalizeTag('  JavaScript  '));

Reply with what is broken and how you would fix it.

1 Like

toLowercase() is broken — JavaScript strings have toLowerCase() (capital C). As written you’ll get TypeError: tag. trim(. . . ). toLowercase is not a function. Fix:

function normalizeTag(tag) {
  return tag.trim().toLowerCase();
}

JS is case-sensitive, so that one character means the method isn’t found at runtime.