JSFiddle - React, Tailwind, and code Playground
CSS
body {
background: #FFF;
}
code {
display: block;
padding: 1em;
background: #F0F0F0;
color: #555;
}
JavaScript
let myVar = 'Hello World';
let undefined = 'string';
document.body.innerHTML = '<p>Value of myVar: <i>(' + (typeof myVar) + ') ' + myVar + '</i></p>';
document.body.innerHTML += '<hr><code>CHECKING (typeof myVar === undefined)<br></code>';
if (typeof myVar === undefined) {
document.body.innerHTML += '<code>true</code>';
} else {
document.body.innerHTML += '<code>false</code>';
}
document.body.innerHTML += '<hr><code>CHECKING (typeof myVar === \'undefined\')<br></code>';
if (typeof myVar === 'undefined') {
document.body.innerHTML += '<code>true // This is the correct result</code>';
} else {
document.body.innerHTML += '<code>false // This is the correct result</code>';
}