Jump to content

Try & Catch


Mikeyham

Recommended Posts

Why is there a "+" before the equal sign in this try & catch statement?

catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Error description: " + err.description + "\n\n";  txt+="Click OK to continue.\n\n";  alert(txt);  }

~Thanks!

Link to comment
Share on other sites

x = 3; y = 7; x += y; // x returns 10x = "hello"; y = ", world"; x += y; // x returns "hello, world"x += y is shorthand for x = x + ySometimes programmers like to add strings in parts for easier updates and debugging.

Link to comment
Share on other sites

I see. I also have another question about the Try & Catch tutorial.

catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Click OK to continue viewing this page,\n";  txt+="or Cancel to return to the home page.\n\n";  if(!confirm(txt))	{	document.location.href="http://www.w3schools.com/";	}

Why is there an "!" before the word "confirm" and, if we are confirming, why is it that when you hit cancel it runs the code?

Link to comment
Share on other sites

I see. I also have another question about the Try & Catch tutorial.
catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Click OK to continue viewing this page,\n";  txt+="or Cancel to return to the home page.\n\n";  if(!confirm(txt))	{	document.location.href="http://www.w3schools.com/";	}

Why is there an "!" before the word "confirm" and, if we are confirming, why is it that when you hit cancel it runs the code?

Because "!" means "not". It returns the opposite value of the variable that it's negating.If confirm(txt) is true, !confirm(txt) is false.
Link to comment
Share on other sites

Because "!" means "not". It returns the opposite value of the variable that it's negating.If confirm(txt) is true, !confirm(txt) is false.
Coolio. That's all. Thanks for the help!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...