Akin to the ternary operator, if you just want to quickly evaluate something, and don't really care about the inverse situation, check out guards!
They're contextually similar to the ternary operator and I honestly have found more use-case for this in the past than ternaries:
//a variable to test with let a = 'a'; //condition && result a === 'a' && console.log('yes it does!');
Keep in mind, like the ternary operator, you should avoid complex logic in the block that is evaluated when your condition is met:
//a variable to test with let a = 'a'; //condition && result // !! THIS WON'T WORK !! a === 'a' && ( console.log('did this work?') console.log('no :(') );
Thank you !!!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Akin to the ternary operator, if you just want to quickly evaluate something, and don't really care about the inverse situation, check out guards!
They're contextually similar to the ternary operator and I honestly have found more use-case for this in the past than ternaries:
Keep in mind, like the ternary operator, you should avoid complex logic in the block that is evaluated when your condition is met:
Thank you !!!