JSFiddle - React, Tailwind, and code Playground

by Abid Akhtar

JavaScript

var myObj = {name: "John", age: 31, city: "New York"};

var promiseTest = new Promise(function (resolve) {
    // JSON.parse will throw an error because of invalid JSON
    // so this indirectly rejects
    //resolve(JSON.parse(JSON.stringify(myObj)));
    //resolve(JSON.parse(JSON.stringify(myObj)));
    resolve(JSON.parse("json"));
    
});

promiseTest.then(function (data) {
    alert("It worked!" + data);
}, function (error) { //error handler
    alert(" I have failed you 1st: " + error)}).
    catch(function(error){alert(" I have failed you 2nd: " + error)
});