Hi Everybody!
Good day
I like to know some JavaScript definitions are following:
try_catch_statement:
<html>
<head>
<script type="text/javascript">
var txt="";
function message()
{
try
{
adddlert("Welcome guest!");
}
catch(err)
{
txt="There was an error on this page.\
\
";
txt+="Error description: " + err.description + "\
\
";
txt+="Click OK to continue.\
\
";
alert(txt);
}
}
</script>
</head>
<body>
<input type="button" value="View message" onClick="message()" />
</body>
</html>
Please see the codes above and give me the following answer:
# What is “txt”? Why I should use this?
# What is “There was an error on this page.\
\
”? What is .\
\
?
# What is “txt+="Error description: " + err.description + "\
\
";” here? I mean
txt+,
Error description:,
err.description and
"\
\
"?
# What is “onClick="message()” as well?
throw_statement:
```html4strict
<html>
<body>
<script type="text/javascript">
var x=prompt("Enter a number between 0 and 10:","");
try
{
if(x>10)
{
throw "Err1";
}
else if(x<0)
{
throw "Err2";
}
else if(isNaN(x))
{
throw "Err3";
}
}
catch(er)
{
if(er=="Err1")
{
alert("Error! The value is too high");
}
if(er=="Err2")
{
alert("Error! The value is too low");
}
if(er=="Err3")
{
alert("Error! The value is not a number");
}
}
</script>
</body>
</html>
What is “else if(isNaN(x))”? Why I should use it?
No more, I am waiting for your kind response.
Thank you.