Test whether a string representing an object n-levels deep is available I was writing some JavaScript that depended on several global variables being present.

I read about the "guard pattern" from a StackOverflow answer but since I need to check for multiple objects it quickly becomes quite tedious to have lines like this everywhere:

if (foo &amp;&amp; foo.bar &amp;&amp; foo.bar.baz) {
    // access foo.bar.baz
}


I wanted to replace the above with:

if (isAvailable("foo.bar.baz")) {
    // access foo.bar.baz
}


Here is the implementation for isAvailable:

// test whether a string that represents an object in a certain
// context (using dot notation) of n-levels deep is available
function isAvailable(s,context) {
    var aSplit, ob;

    if (s === undefined || s === null) {
        return false;
    }

    aSplit = s.split('.');
    ob = context[aSplit.shift()];
    while (ob !== undefined &amp;&amp; aSplit.length &gt; 0) {
        ob = ob[aSplit.shift()];
    }
    return typeof ob === "object";
}


Here is a JSBin: http://jsbin.com/jokowomepo/edit?js,console

Also, I should mention that I am only interested in solving this problem with vanilla JavaScript...no libs.

My implementation seems to work, but I'd be interested if there are improvements that could be made.

Any feedback?
This maybe a matter of taste, but I'm not a big fan of slicing arrays.
I find this alternative implementation using a for loop and without array slicing a bit simpler:

function isAvailable(s,context) {
    var aSplit, ob, i;

    if (s === undefined || s === null) {
        return false;
    }

    aSplit = s.split('.');
    ob = context;
    for (i = 0; ob !== undefined &amp;&amp; i &lt; aSplit.length; ++i) {
        ob = ob[aSplit[i]];
    }
    return typeof ob === "object";
}