In Javascript, the parameter in the function is optional. If the caller did not pass in the parameter value (as shown in test1 function), then, the value of "a" is "undefined". So, each time before you are using the incoming parameter value, make sure that you check it before using it.
You may copy the following tags into any html file and then debug it in Visual Studio.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function check(a) {
var i = 0;
if (a) {
i = a;
}
else {
i = -1;
}
}
function test1() {
check();
}
function test2() {
check(12345);
}
function test3() {
check(null);
}
</script>
</head>
<body>
<input type="button" name="name" value="test1" onclick="return test1();" />
<input type="button" name="name" value="test2" onclick="return test2();" />
<input type="button" name="name" value="test3" onclick="return test3();" />
</body>
</html>
Subscribe to:
Post Comments (Atom)
We are moving
We are moving this blog to our new blog site: https://ciysys.com/blog/nodejs.htm
-
Overview Usually, we start developing a new system with designing database and then writing codes. If you are not a fan of ORM, you will h...
-
Below is the sample HTML which will hide the URL at the page header when printing with Javascript. <html moznomarginboxes > ...
-
You can draw a simple pie chart & doughnut chart with SVG + CSS. This is quite simple and straight forward. But the limitation is that i...
No comments:
Post a Comment