I came accross value = String(event.target.value || "") when a textinputs keyup/keydown event is fired.
But i’m not sure when the event.target.value is not a string? Is this possible? When is something else passed off as an event.target.value?
If the
event.targetelement is not an input type element, it will not have avalueproperty. For example, if I click adivthenevent.targetis a div which does not havevalue.Wrapping
event.target.value || ''inString()is not necessary as it will always be either value (which is always a string orundefined) or the empty string in the case that value isundefined.See this fiddle for a demonstration.