JSFiddle - React, Tailwind, and code Playground
by bilbobaggins
JavaScript
// global variable
var allUserData = [];
function getInput(options, callback) {
allUserData.push(options);
callback(options);
}
// When we call the getInput function, we pass logStuff as a parameter.
// So logStuff will be the function that will called back (or executed) inside the getInput
getInput({name : "Rich", speciality : "JavaScript"
}, logStuff);
// name: Rich
// speciality: JavaScriptfunction
// generic logStuff function that prints to console
function logStuff(userData) {
if (typeof userData === "string") {
//console.log(userData);
} else if (typeof userData === "object") {
for (var item in userData) {
console.log(item + ": " + userData[item]);
}
}
}