[.js] Conditional Statement Shortcuts
If you’re writing a simple if statement that sets one variable to one of two conditions, you can use something called a ternary operator. It’s basically a one line conditional statement.
Say you have some JavaScript that checks a user’s login status:
var status;
if (login) {
status = 'signed in';
} else {
status = 'signed out';
}
You can rewrite it simply as:
var status=(login)?'signed in':'signed out';
Pretty simple, eh?