Javascript Debugging Tips

  • To dump out random objects
    console.log(JSON.stringify(obj))

    if that didn’t work:

    console.log("my object: %o", obj);

    A straight console.log(obj) will often show [object Object] which doesn’t tell you anything!

  • Use hasOwnProperty to test if one can access this property in an object
    if (obj.hasOwnProperty("id")){
        console.log(obj.id);            
    }