var a = 1; var d; function test() { b = 5; var c = 7; } function log(txt){ $('#console').html($('#console').html() + "<br/>"+ txt); } $(document).ready(function() { test(); if(typeof a != 'undefined')log("a result::" + a); if(typeof b != 'undefined')log("b result::" + b); if(typeof c != 'undefined')log("c result::" + c); if(typeof d != 'undefined')log("d result::" + d); if(typeof d == 'undefined'){ log("d is undefined"); } });
<div id="console"> </div>