JSFiddle - React, Tailwind, and code Playground
HTML
<button>Greet</button><br><br>
JavaScript
// use this function when you create variables.
// instead of var someVariable = "someValue";
// use var someVariable = v("someValue");
// this will output the value, and still assign the variables as you'd expect.
function v(value) {
var outputText = (typeof value === "object" && value.constructor === Object && window.JSON) ? JSON.stringify(value) : value;
document.body.appendChild(document.createTextNode(outputText));
document.body.appendChild(document.createElement("br"));
return value;
}
// create and output a "greeting" variable
var greeting = v("Hello There!");
// create and output an array of primary colours
var primaries = v(["red", "green", "blue"]);
// say the "greeting" variable when you click the button
document.getElementsByTagName("button")[0].onclick = function() {
alert(greeting);
};