When using a ternary operator —  or any abbreviation  — consider who will be reading your code. Let's consider an example: This code returns "Welcome back Stephen" if name is equal to Stephen; otherwise, it returns "Welcome" and then whatever value the variable name contains. When the callback function has one short statement, the arrow function is a good option too, because it creates short and light code. – Javascript shorthand for cleaner code “A few ways to save on some bytes in your Javascript code, as well as making it more readable […] Craig says: 29 May 2010 at 04:32 am For example, consider this set of nested if/else statements: This code assigns one of five possible values to a single variable. Here we will explain the if..else statement. (So while you could do this if both method happened to return the same value, you shouldn't invoke it for the side-effect purposes only). They can operate on expressions of any type , not just booleans. new Function way … Laravel If-Else, Switch Case and shorthand Ternary operator example The conditional ternary operator in JavaScript assigns a value to a variable based on some condition and is the only JavaScript operator that takes three operands. This is also called a ternary operator. In other words, the HTML and CSS assets are given to you in a starter file but you’d have to build the app.js file. javascript by Excited Eland on Apr 15 2020 Donate . javascript if shorthand . This is not just a PDF page, it's interactive! Conditional statements are used to decide the flow of execution based on different conditions. Output. I had no reason to think that this wasn't possible, it's just kind of cool to see it work: