blog post

At the moment, there is something wrong with the if statement. The ternary operator lets us write shorthand if..else statements exactly like you want.

Source Code

var hasName = (name == "true") ? "Y" : "N" ;

It looks like:
(name === 'true') - our condition
? - the ternary operator itself
'Y' - the result if the condition evaluates to true
'N' - the result if the condition evaluates to false
So in short (question)?(result if true):(result is false) , as you can see - it returns the value of the expression so we can simply assign it to a variable just like in the example above.

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Comments (1)

  • Edgell

    Tuesday, 15 November, 2016 11:05 PM

    Thank you

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information