How can I add debugging code to my JavaScript?

HTMLJavascriptProgramming Scripts

To add debugging code to JavaScript, use the alert() or document.write() methods in your program. For example,

var debugging = true;
var whichImage = "widget";

if( debugging )
alert( "Calls swapImage() with argument: " + whichImage );
var swapStatus = swapImage( whichImage );

if( debugging )
alert( "Exits swapImage() with swapStatus=" + swapStatus );

Examine the content and order of the alert() as they appear, you can examine the health of your program very easily.

raja
Published on 23-Feb-2018 16:13:27
Advertisements