JSFiddle - React, Tailwind, and code Playground

by kmendes

JavaScript

console.log(typeof undefined); //undefined
var c;
console.log(c == undefined); //true
var undefined = "und"; //yes, it works!
console.log(c == undefined); //false, not a good idea
(function() {
    var b;
    console.log(typeof undefined); //string
    console.log(undefined); //und
    console.log(b === undefined); //false
    console.log(typeof b === "undefined"); //true, this is safe
    (function(undefined) { //resets undefined, nice!
        console.log(typeof undefined); //undefined
        console.log(undefined); //undefined
        console.log(b === undefined); //true, but still not a good idea
        console.log(typeof b === "undefined"); //true, typeof is always safe.
    })()
})();

/* Conclusion: always use typeof because that's gonna be safe, but the undefined parameter is a good pattern to keep the code inside the modules safe in case someone compares the variable to undefined */