Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is an event.target.value not a string?

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?

like image 914
Tarang Avatar asked Feb 06 '13 18:02

Tarang


1 Answers

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.

like image 200
jbabey Avatar answered Oct 05 '22 07:10

jbabey