
Instead of having to check if something is true with an if
statement, you can use the &&
operator:
var isReady = true;
function doSomething(){
console.log("Yay!");
}
// LONGER FORM
if(isReady){
doSomething();
}
// SHORTHAND
isReady && doSomething();
Source
https://medium.com/geekculture/20-javascript-snippets-to-code-like-a-pro-86f5fda5598e