Skip to content

Instantly share code, notes, and snippets.

@thebigdatajedi
Created December 17, 2022 13:41
Show Gist options
  • Save thebigdatajedi/2806adf8cf110b810f91848b27bc350f to your computer and use it in GitHub Desktop.
Save thebigdatajedi/2806adf8cf110b810f91848b27bc350f to your computer and use it in GitHub Desktop.
ternary explanation with example
//This is how a ternary operator works:
//<condition to check> ? <what happens if the condition is true> : <what happens
//if the condition is false>;
//Credit Union System example with evaluating fees.
function getFee(isMember: boolean): string {
return (isMember ? '$2.00' : '$10.00');
}
let fee = getFee(true);
console.log(fee); //this would print $2.00 to the console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment