loading...

re: [PT-BR] Simple concepts of Modern JavaScript VIEW POST

FULL DISCUSSION
 

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 :(')
);
 
code of conduct - report abuse