JSFiddle - React, Tailwind, and code Playground
JavaScript
$x = "hi#1";
alert($x); //alerts hi#1 as $x is declared globally
function hi() {
var $x = "hi#2";
alert($x);
}
hi(); //alerts hi#2 as $x within the function scope is hi#2
alert($x); //alerts hi#1 the previous $x was defined within the scope.
function hi3() {
$x = "hi#3";
}
hi3(); //replaces global vairiable $x to hi#3
alert($x); //alerts hi#3