Reputation: 1609
Javascript allow using a boolean on arithmetic expressions but I want to know if is a good practice to do so.
For example:
var expectedGuests = 100 * ((day==='Friday')*1.5 || 1);
I know this can be written in different ways but I want to know if using this means a negative or maybe positive impact on performance, navigator compatibility or any other important matter that I should be aware of.
Upvotes: 2
Views: 1156
Reputation: 104775
Use a ternary, it'll be cleaner:
var multiplier = day === 'Friday' ? 1.5 : 1;
var expectedGuests = 100 * multiplier;
Upvotes: 7