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...
-
I'm working on an attendance audit screen which allows the user to single click to confirm the selection and double click to create a re...
-
You cannot achieve the fixed row and column with HTML + CSS. You need the Javascript as well. Below is the HTML, CSS and Javasript th...
No comments:
Post a Comment