How can I stop a Javascript from being interpreted after a certain point?

dom-events, javascript, jquery, jquery-plugins

Solution

Just return.

if (window.location.hash) {
    window.location = window.location.hash.substring(1);
    return;
}

Note that the script will still be parsed until the end, so it has to be valid JavaScript all the way through. But I think you meant "interpreted" in the title.

Problem

The first few lines of my script look like: ``` if (window.location.hash) { window.location = window.location.hash.substring(1); } ``` I'd like to have the entire script "skipped" if this statement returns true. Is there any way to do this other than putting my entire script in a giant if statement?

Original source