Let’s say you have an object, TRACK, for tracking
TRACK = {};
TRACK.pageName = pageName || TRACK.buildPageName();
This would work fine if there was this somewhere before it:
var pageName = "Home";
Let’s assume a way to fix this is:
TRACK.pageName = (typeof pageName != 'undefined' ? pageName : TRACK.buildPageName());
Is there a better practice for doing this with large javascript objects?
if you are in a browser, you can do
window.pageNameto check the pageName value.But it’s not really a “better” pratice. It’s just a second way to do this. Using
typeofis fine too.