Jump to content

Need explanation of inline Ternary operator


SnakesBite101

Recommended Posts

I understand how Ternary operators work but i came across an inline one and im trying hard to figure out what each operation is doing. Can anyone please explain this to me: var hadRelations = false,isSure = false, presidentQuote = hadRelations ? "Did not have relations" : isSure ? "Did not have relations" : "I admit"; "I admit" is the value returned 1st i dont understand why they use "," instead of ";" to terminate variable definitions. But what is the Ternary doing? i don't understand the use of the first two strings in the operation. What is the concept here, what would make the return value equal to either of the first two strings, instead of the last one? Thanks

Link to comment
Share on other sites

You can sayvar a;var b;var c;or you can sayvar a,b,c;or you can sayvar a, b, c; forvar answer = x ? y : z; if x is true then answer = yif x is false then answer = z forvar answer = x ? y : z ? a : b if x is true then answer = yif x is false and z is true then answer = aif x is false and z is false then answer = b

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...