Use `(typeof onsuccess === 'function') && onsuccess();` as you do below.