When is an event.target.value not a string?
If the event.target
element is not an input type element, it will not have a value
property. For example, if I click a div
then event.target
is a div which does not have value
.
Wrapping event.target.value || ''
in String()
is not necessary as it will always be either value (which is always a string or undefined
) or the empty string in the case that value is undefined
.
See this fiddle for a demonstration.
Tarang
Tail.sh is a complete Analytics solution for Meteor. Plug and Play/no coding required. Automatic event binding too! Give it a try: meteor add tail:core Then load your browser up to finish up the setup. (Also check https://tail.sh/getting_started for more info) Also worked on https://getfirststep.com (Australian Investing Startup)
Updated on July 30, 2022Comments
-
Tarang almost 2 years
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 anevent.target.value
?