How can I stop javascript interpretation after a certain point?

The first few lines of my script look like this:

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

I would like the whole script to be skipped if this statement returns true. Is there any way to do this other than putting my entire script in a giant if statement?

+3
source share
1 answer

Just give it back.

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

Note that the script will still be parsed to the end, so it must be valid JavaScript in its entirety. But I think you meant "interpreted" in the title.

+5
source

Source: https://habr.com/ru/post/1730735/


All Articles