Ad
  • Custom User Avatar
  • Default User Avatar

    Thanks for your advice :)

    I'm still learning new shorthands in JS and I've seen that a couple of times, but I keep forgetting about this :D

    I'll try using it next time. Thanks again :)

  • Default User Avatar

    When you have a situation where the condition is the same as the truthy expression in a ternary, you can reduce this to just use an ||(or) statement.

    e.g. return data[language] || 'Welcome';

    This works because if the first expression is truthy, then the operation short circuits and the first expression is returned. If the first expression falsy and the second statement is truthy, the second statement gets returned. In the case where both expressions are falsy, this will return false. The last scenario won't happen in this case because your second expression is a constant truthy value.