function toInt(x) { return Number(x) || 0; } alert(typeof(toInt(1))); alert(toInt('2.5')); alert(toInt('test'))