DEV Community

Discussion on: Don't name your global JavaScript function 'clear'

Collapse
 
puritanic profile image
Darkø Tasevski • Edited

Or just don't put anything in the global scope at all 🙂 But if you must do it, just prefix your variable/function name with something unique., like so:

function GLOBAL_FN__clear() {
            document.getElementById('result').innerHTML = '';
}

Interesting post tho 👍

Collapse
 
nikola profile image
Nikola Brežnjak

Yes, I definitely agree, and thanks for the tip. I came across this, and wanted to share as at first I was puzzled with what's happening :), and it surely can help beginners.