Is it good practice to use "return false;" to basically say do nothing in an if statement? For example:
if (navigator.userAgent.match(/iPad/i) != null) {
return false;
} else {
//Usual script here
}
just wondering if there are any downfalls to this. I can use the if statement without the else but i'm just wanting to get insight on this. I have a plugin that i do not want running on iPad and so I'm wrapping it in the conditional. any comments would be appreciated!
Group 1 will say it is horrible practice since it is hard to follow.
Group 2 will say do it.
Group 3 will say do it, but in 1 line
Group 4 will say do not use the else
Group 5 will say to do not use the return, just use the if around the code you want to run. AKA:
if (navigator.userAgent.match(/iPad/i) === null) {
//Usual script here
}
In my experience only if you were actually looking for the false to be returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With