<script> function test(name) { if (typeof window[name] === "function") { window[name](); } else { alert("Function not declared") } } function one() { alert('One'); } test("one"); test("two"); </script>