Using && and ||

jonathan martinez
Jul 23, 2017 · 1 min read

Short story..

&& moves forward as long as the previous object is truthy.

|| moves forward as long as the previous object is falsey.

tip: If a condition is true, then the ! Logical will make false, therefore if you want to see the value in your terminal you can use !! before the line of code your code.

If you type this in your terminal this is what the result should be:

<script src=”//repl.it/embed/Jeqa/0.js”></script>

5 Five is truthy which will return true

<script src=”//repl.it/embed/Jepa/2.js”></script>

nill is falsey which will return false

<script src=”//repl.it/embed/Jepa/4.js”></script>

!!”hello” the string hello will return true

<script src=”//repl.it/embed/Jepa/3.js”></script>

5 && 6 5 is true && moves forward and prints 6

<script src=”//repl.it/embed/Jepa/6.js”></script>
“hello” return true, 5 return true, and true return true

<script src=”//repl.it/embed/Jepa/7.js”></script>

Here is where the magic happens. false does not return true which mean && does not advance and that line of code returns false

<script src=”//repl.it/embed/Jepa/8.js”></script>

77 return && moves forward, nil does not return true && does not move forward returning nill.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade