Javascript returns false in if statements

Is it good to use "return false"; basically say do nothing in if statement? For instance:

if (navigator.userAgent.match(/iPad/i) != null) {
    return false;
} else {
    //Usual script here
}

just wondering if there are any problems with this. I can use the if statement without else, but I just want to get an idea about this. I have a plugin that I don’t want to run on the iPad, and so I wrap it in conditional. Any comments would be appreciated!

+5
source share
6 answers

Group 1 will say that this is a terrible practice, as it is difficult to implement.

Group 2 will say do it.

Group 3 will say do it, but in line 1

Group 4 will say don't use else

5 , , if, . AKA:

if (navigator.userAgent.match(/iPad/i) === null) {
    //Usual script here
}
+9

, .

+4

, :

if (navigator.userAgent.match(/iPad/i) != null) return false;
//Usual script here

" "... , . , , -, , .

, , false , , , , return true;.

+2

, - . "" if, . :

if (navigator.userAgent.match(/iPad/i) == null) {
    //Usual script here
}

, "" ( ).

0

snkmchnb, . , :

!(a && b) = !a || !b
!(a || b) = !a && !b

, , . ,

!( (a && b || c) && (d || e) || f) =
    !((a && b || c) && (d || e)) && !f =
    (!(a && b || c) || !(d || e)) && !f =
    (!(a && b) && !c || !d && !e) && !f =
    ((!a || !b) && !c || !d && !e) && !f

, . , "< =" " > "

! (long_expression):

if (long expression)
{
}
else
{
  //do stuff here
}
0

-, ,

var window.__page_loaded__;
var Loadpage = function ()
{
    if(window.__page_loaded__ != undefined)
    {
         return; //The page has already laoded
    }

    //Proceed to load the page
}

return;, , else, , Loadpage() - , .

0

All Articles