Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30093
| Path | csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Tony Johansson" <johansson.andersson@telia.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Can somebody explain this code |
| Date | Wed, 23 Mar 2016 22:51:08 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 34 |
| Message-ID | <ncv2un$mlp$1@dont-email.me> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; format=flowed; charset="iso-8859-1"; reply-type=original |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 23 Mar 2016 21:48:07 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="bf7f66bed791bd77f0e405a5a6cf80a9"; logging-data="23225"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aLQJ3C5HB3XnI/0ks75YF" |
| X-Newsreader | Microsoft Windows Mail 6.0.6002.18197 |
| Cancel-Lock | sha1:3pm7DpwQE9QDXlY3vvztGVzoU98= |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| X-Mimeole | Produced By Microsoft MimeOLE V6.0.6002.18463 |
| Xref | csiph.com comp.lang.javascript:30093 |
Show key headers only | 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 | Next — Next in thread | Find similar | Unroll 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