I\'ve created a function that checks if 2 words are anagrams, but I want to make it better. I feel the declaration of the counter after in the if statement is not quite well, if
Your code returns true for strings 'aabb' and 'abcc', which are not anagrams. You can just sort the strings and check if they're equal:
function checkAnagram(string1, string2) { return string1.toLowerCase().split("").sort().join("") === string2.toLowerCase().split("").sort().join("") }