Guest User

Untitled

a guest
Dec 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. let sober = true;
  2. let isSober = () => {
  3. console.log('This person is completely sober.');
  4. }
  5. let isDrunk = () => {
  6. console.log('This person had too much alcohol.');
  7. }
  8.  
  9. // A normal if statement
  10. if(sober) isSober(); // This person is completely sober.
  11.  
  12. // Above can be done using '&&' operator
  13.  
  14. sober && isSober(); // This person is completely sober.
  15.  
  16. // Using logical OR - '||' operator
  17. sober = false;
  18. // A normal if statement
  19. if(!sober) isDrunk(); // This person had too much alcohol.
  20.  
  21. sober || isDrunk(); // This person had too much alcohol.
  22.  
  23. // In this specific example, the logical OR could also be used to set a defalt value
  24.  
  25. const getBio = (name, year, breed) => {
  26. name = name || 'John';
  27. year = year || 2018;
  28. breed = breed || 'Beagle';
  29. }
Add Comment
Please, Sign In to add comment