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

How to use SUM() in MySQL for calculated values -

ios - IBOutlet for image button not correctly referencing button after recreating outlet -

java - AEM: 403 Forbidden occurs when call a Post servlet -