JSFiddle - React, Tailwind, and code Playground

by deepak sisodiya

HTML

This is a simple snippet, but there are already 2 global items: sum , product. This could get us in trouble if we start using third-party libraries. What would happen if they use the same names? Well, if they are included after our script, they will overwrite our variables and function. Bad! If they’re included before our script, we’re overwriting their variables, which is also bad, since we’ll probably break the library.

JavaScript

// by default all things in javascript is global

var alert  = function (str) {
   var st = document.createTextNode(str);
   var p = document.createElement('p');
   p.appendChild(st);
   document.querySelector('body').appendChild(p);
}

function firstName(name) {
    return alert(name)
}
function lastName(name) {
    return alert(name)
}

firstName("deepak")
lastName("sisodiya")