There are times when you want your Javascript to have different behaviour depending on which mode the page is in. For example, in design mode, you may want to turn off some functionality or create a "preview" feature where some visual cues are provided.
Here's a little Javascript function to detect whether or not the web part page is in design mode. The script checks the value of two hidden fields set by SharePoint.
function IsInDesignMode()
{
if(document.getElementById("MSOLayout_InDesignMode").value == '1') return true;
if(document.getElementById("MSOTlPn_SelectedWpId").value != "") return true;
return false;
}