Skip to content

Instantly share code, notes, and snippets.

@tyrotinal
Created October 5, 2013 21:20
Show Gist options
  • Save tyrotinal/6846183 to your computer and use it in GitHub Desktop.
Save tyrotinal/6846183 to your computer and use it in GitHub Desktop.
js - ternary operator
var a = 2;
var b = 3;
var c = 4;
function sayHi(){
console.log("hello - a");
}
function sayHiB(){
console.log("hello - B");
}
function sayHiC(){
console.log("hello - C");
}
function sayHiElse(){
console.log("hello - Else");
}
a == 3? sayHi() : b == 4? sayHiB() : c == 5? sayHiC() : sayHiElse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment