Shobhit Verma
Shobhit Verma

Reputation: 834

Is it required to keep return in js function()

Is it required to keep return in js function()

function EshopProcessOrder() {
    window.location = "http://www.google.com/";
    return false;
}

Thanks in advance

Upvotes: 1

Views: 78

Answers (1)

Tushar
Tushar

Reputation: 87203

No. If you don't want to return anything from the function you can skip it. But by default undefined will be returned.

So, if you don't have return statement in the function javascript will by default add return undefined at the end of the function.

return false is used to stop the default action of the element and stop the event propagation to the ancestors.

In your case,

function EshopProcessOrder() {
    window.location = "http://www.google.com/";
    return false;
}

return false will never executed, since the page is redirected before reaching that statement.

Upvotes: 2

Related Questions