Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Code seems to be logical but returns empty string
Message
De
29/07/2015 09:56:22
 
 
Information générale
Forum:
Javascript
Catégorie:
Débogage
Divers
Thread ID:
01622609
Message ID:
01622638
Vues:
52
This message has been marked as the solution to the initial question of the thread.
>>>Hi everybody,
>>>
>>>This should be simple but somehow it eludes me.
>>>
>>>I have this code in JavaScript which seems very logical and simple to me:
>>>
>>>
>>>formTitle = formTitle + $scope.isNew ? '' : ' (' + currentmax4sale.id + ')';
>>>
>>>I am debugging it and right before this line of code the formTitle has value. Right after this it becomes a blank string, although $scope.isNew = false.
>>>
>>>My intent is to add an extra string in case of the existing row.
>>>
>>>Where am I making the mistake for such a simple assignment?
>>>
>>>I am guessing I am running into some weird operator precedence issue here.
>>>
>>>Thanks in advance.
>>>
>>>In the meantime I'll get rid of the inline iif and add IF statement instead.
formTitle = formTitle + ($scope.isNew ? '' : ' (' + currentmax4sale.id + ')');
>
>Well, I already re-wrote the code. I was mostly interesting in the explanation of that behavior.

Without the brackets the value being tested by the '?' is formTitle+$scope.isNew - that results in a string which is cast to a Boolean. Any non-empty string evaluates to true.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform