4
I am studying Act and I came across the following expression:
{this.state.text.split(' ').map((word) => word && '').join(' ')}
This summary expression will print a pizza for each word inserted in the text:
Follow the example:
https://facebook.github.io/react-native/docs/handling-text-input
Well the doubt is not about Act but about what will be returned in this function:
(word) => word && ''
This function receives a word word
and if the word is valid then a pizza will be returned
But in case I do this:
(word) => '' && word
Word will be returned and not a pizza.
But shouldn’t this condition return a bool, since it is a boolean condition? And why always the last clause that is returned? Or this has to do with the Map function?
So it’s some kind of recursion? In the case of if it checks the first clause, if it is true it passes to the next one, but as there is no if and not a while then it returns the clause instead of a bool?
– Vinicius Morais
@Viniciusmorais more or less that. It uses the value of the last clause as if it were a Boolean, even if it is not. There is an analogous behavior with the
||
also.– Victor Stafusa