Skip to content

Instantly share code, notes, and snippets.

@Blazing-Mike
Created October 11, 2021 11:52
Show Gist options
  • Save Blazing-Mike/0f1447eb97cccf24b94301da46629869 to your computer and use it in GitHub Desktop.
Save Blazing-Mike/0f1447eb97cccf24b94301da46629869 to your computer and use it in GitHub Desktop.
// Learning ternary operators
// Traditional way
let message;
if (login == 'Employee') {
message = 'Hello';
} else if (login == 'Director') {
message = 'Greetings';
} else if (login == '') {
message = 'No login';
} else {
message = '';
}
// Using ternary operator
let message = (login == "Employee") ? "hello" :
(login == "Director") ? "Greetings" :
(login == "") ? "No login" : "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment