Advertisement
karlakmkj

Short-circuit evaluation

Dec 8th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let tool = ''; //since is empty string, it will take the default value of 'pen' as tool is falsy.
  2.  
  3.  
  4. // Use short circuit evaluation to assign writingUtensil variable below:
  5. let writingUtensil = tool || 'pen';
  6.  
  7. console.log(`The ${writingUtensil} is mightier than the sword.`);
  8.  
  9. /*
  10. The variable writingUtensil will be assigned the actual value of tool if is truthy,
  11. while it will be assigned the value of 'pen' if tool is falsy.
  12. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement