Skip to content

Instantly share code, notes, and snippets.

@towerofnix
Created November 5, 2015 23:49
Show Gist options
  • Save towerofnix/313ebbf2cf3b93c338d4 to your computer and use it in GitHub Desktop.
Save towerofnix/313ebbf2cf3b93c338d4 to your computer and use it in GitHub Desktop.
Faking JavaScript syntactic sugar
/*\
| Faking JavaScript syntactic sugar
|
| Feel free to fork this to add more information!
|
| Remember to utilize ES6 things, because why not?
| It's standardized!
\_
| Contents:
|
|
|
\*/
/*\~
$ifstatements$
IF STATEMENTS
Contents:
- $ifstatements:1$ basic sugaring
- $ifstatements:2$ using || as sugar for if-not
~\*/
// $ifstatements:1$
// If statement syntactic sugar
// This is how you would do it with a block of code:
(true)&&(()=>{
console.log("Hello world!");
})();
(false)&&(()=>{
console.log("Nooo..");
})();
// But arrow functions support one liners so we can do this:
(true)&&(()=>
console.log("Hi y'all!")
)();
(false)&&(()=>
console.log("If this appears..")
)();
// We can make it even shorter like this:
(true)&&(
console.log("What's up guys?")
);
(false)&&(
console.log("But really?")
);
// This is just syntactic sugar of course. ;)
// $ifstatements:2$
// If not statement syntactic sugar
// Here's an if-not statement:
(true)||(
console.log("A")
);
(false)||(
console.log("B")
);
// More soon???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment