javascript check if object is defined and not null