Using your if's in a shorter, simpler and cooler way

#13

JS

July 16, 2019

So, for today, i decided to show you a little simple tip on how to write some of your if statements in a shorter way. This can help you clean up your code a little bit, making it easier for the eye.

Basically you just have to follow this structure - (some condition) && (some instructions) - for example: someVar > someOtherVar && console.log('yeah') This will log 'yeah' if someVar is bigger than someOtherVar.

var someString = 'Just some random truthy value' if(someString){ console.log('hmmm...') } someString && console.log('shit works!')

In this example we just create two if statements, one with the traditional method and the other with this one, to check if 'someString' is truthy. As we can see, both cases are logged on the console.
Have a nice one! 😁👌