javascript - Checking if object not null before accessing property -


this question has answer here:

var how = $('how'); var id = $('myid'); if ((how != null && !how.value.blank()) || myid != null) {     return true; } else {     alert('error'); } 

is there easier way check not null , checking if value of element blank without having both != null , calling value?

since null falsy, shorter version be

if((how && !how.value.blank()) || myid != null) {    ... } 

note above code , own snippet both assume if how exists, have property called value, , throw exception if not case.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -