Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30093

Can somebody explain this code

From "Tony Johansson" <johansson.andersson@telia.com>
Newsgroups comp.lang.javascript
Subject Can somebody explain this code
Date 2016-03-23 22:51 +0100
Organization A noiseless patient Spider
Message-ID <ncv2un$mlp$1@dont-email.me> (permalink)

Show all headers | View raw


I know that functions behave much like variables such as
var myFunc = function() { alert("This is my anonymous function");}

But in the code below when I have (a && b)(); only function b is called and
when I have  (a || b)();  only function a is called

If a = null in this example (a || b)();   then b is called.

Can somebody explain what is happening here when I have this kind of strange 
looking code.
I do this just because of some testing how it works.

If both a and b is null I get error because then the expression does not 
produce a function value which is correct.

<script type="text/javascript">
        function a()
        {
            alert("function a");
        };

        function b()
        {
            alert("function b");
        };

       (a && b)(); //here only b is called

        (a || b)(); // here only a is called

    </script>

//Tony 

Back to comp.lang.javascript | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Can somebody explain this code "Tony Johansson" <johansson.andersson@telia.com> - 2016-03-23 22:51 +0100
  Re: Can somebody explain this code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-24 20:30 +0100
    Re: Can somebody explain this code Aleksandro <aleksandro@gmx.com> - 2016-03-24 20:19 -0300
      Re: Can somebody explain this code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-27 22:44 +0200
        Re: Can somebody explain this code Aleksandro <aleksandro@gmx.com> - 2016-03-27 18:22 -0300
          Re: Can somebody explain this code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-28 01:07 +0200
            Re: Can somebody explain this code Aleksandro <aleksandro@gmx.com> - 2016-03-27 20:26 -0300
              Re: Can somebody explain this code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-04 05:51 +0200
                Re: Can somebody explain this code "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-05-04 08:55 +0200
                Re: Can somebody explain this code Aleksandro <aleksandro@gmx.com> - 2016-05-07 13:02 -0300

csiph-web