Meaning of ? in conditional operators

Hi guys , I hoping that someone can help me to understand the following syntax, or provide a link for reading material :slight_smile:

I have this piece of code: (for example)

    icon: !'ios') ? 'trash':null


  icon: mode !== 'ios' ? 'mail' : null

What does the “question mark” indicate here ?? and also meaning of ‘trash’: null … I know trash is the name of the icon , but the null part I am confused what it means !

1 Like

In your piece of code ? is used for Ternary operator. In short for checking a condition and apply particular icon name as per the condition satisfied.

In your case maybe, the platform you may checking is if not iOS then apply class type for icon is null.
Maybe for above case programmer don’t want to apply CSS class or icon name for it.
And apply CSS class or icon name -> trash or mail if the platform is other than iOS.

1 Like
if (somethingToTest) {
else {

… translates to …

somethingToTest ? TrueCase() : FalseCase();

This is called a ternary operator as @surajrao mentioned

1 Like

keep in mind that you can’t just say

somethingToTest ? TrueCase();

you have to have both the true and the false cases. :slight_smile:

1 Like

? mean then
: mean else

1 Like