Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // instead of
- const data = getData();
- if (data.error) {
- console.log('There was an error.');
- }
- // Do this
- (data.error) && console.log('There was an error.');
- // or
- isThisTrue && doSomething() || doAnotherThing();
- // So if isThisTrue is true then it will call the doSomething() function, but if it’s false in the first place, doAnotherThing() will be called.
- // Instead of writing this:
- if(truthy){
- return doSomething();
- }else{
- return "I will not do anything";
- }
- // Write this:
- return (truthy && doSomething() || "I will not do anything");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement