DEV Community

Sneachta O'Fuichtard
Sneachta O'Fuichtard

Posted on

What does ? : mean in this line of code?

Total newbie here but can someone explain this line of code?

Items: Text ? this.getFilteredItems(this._allItems) : this._allItems

Thanks
S

Top comments (3)

Collapse
 
1dabdab profile image
Alfred

That is a ternary operator (developer.mozilla.org/en-US/docs/W...)

the line says that, if there is a Text run the function getFilteredItems and if the text is undefined or null, return all the items(this._allItems).

Ternary operator is a simplified and shorter way to do a conditional statement.

Collapse
 
sneachtaof profile image
Sneachta O'Fuichtard

Thanks Alfred

When you say " if there is a Text"
Where is it looking for text?

Collapse
 
ddasb profile image
Damien Da Silva Bregieiro • Edited

This code means :
if(Text){
return this.getFilteredItems(this._allItems)
} else {
return this._allItems
}

It's a simple ternary expression.