function getSecondPart(str) { if(str === undefined || typeof str != 'string' || str.indexOf('-') == -1) return false; return str.split('-')[1]; } console.log(getSecondPart({}); // false console.log(getSecondPart([]); // false console.log(getSecondPart()); // false console.log(getSecondPart('')); // false console.log(getSecondPart('test')); // false console.log(getSecondPart('asdf-test')); // test