Skip to content

Instantly share code, notes, and snippets.

@dantejauregui
Last active January 25, 2018 10:12
Show Gist options
  • Save dantejauregui/5af30df6ea33bb876fbfbd947731b5f7 to your computer and use it in GitHub Desktop.
Save dantejauregui/5af30df6ea33bb876fbfbd947731b5f7 to your computer and use it in GitHub Desktop.
Multiple conditionals: " && " " || "
following this url theory: https://stackoverflow.com/questions/4490274/returning-with
1st Case '&&' :
- return a && b
-Explanation:
Will be equivalent to:
if (a = true) return b;
else return a;
- return a && b && c
-Explanation:
Meaning 1: if "a" is TRUE, will continue the analisis to "b".
If "b" is TRUE, will continue to analize "c".
If "c" is true, RETUNS the "c" value (the last).
Meaning 2: if "a" is TRUE, will continue the analisis to "b".
If "b" is FALSE, will RETURN "b".
And the Analisis of "c" wont make it.
In summary, with a chain of && conditionals: focus in the last element,
because what this conditional TRY TO DO is get the "WHOLE TRUE";
thats why, will iterate to all the elements in order to find all the TRUE possibles.
But, if it find an element FALSE in the middle of the iteration, THIS DATA will be returned and CUT the interation.
2nd Case '||' :
- return a || b
-Explanation:
Will be equivalent to:
if (a = false) return b;
else return a;
- return a || b || c
-Explanation:
Meaning 1: if "a" is FALSE, will continue the analisis to "b".
If "b" is FALSE, will continue to analize "c".
If "c" is FALSE, RETUNS the "c" value (the last).
Meaning 2: if "a" is FALSE, will continue the analisis to "b".
If "b" is TRUE, will RETURN "b".
And the Analisis of "c" wont make it.
In summary, with a chain of || conditionals: focus in the last element,
because what this conditional TRY TO DO is get the "WHOLE FALSE";
thats why, will iterate to all the elements in order to find all the FALSE possibles.
But, if it find an element TRUE in the middle of the iteration, THIS DATA will be returned and CUT the interation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment