I recently needed a way to check if a variable was defined in javascript. This function is exactly analogous to the ColdFusion function IsDefined.
<script language="javascript">
// JavaScript Document
/*
// ///////////////////////////
// isdefined v1.0
//
// Check if a javascript variable has been defined.
//
// Author : Jehiah Czebotar
// Website: http://www.jehiah.com
// Usage : alert(isdefined('myvar'));
// ///////////////////////////
*/
function isdefined( variable)
{
return (typeof(window[variable]) == "undefined")? false: true;
}
</script>