Functions with Parameters
Defining Functions with Parameters
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<script type="text/javascript">
function myFunc(name, weather) {
document.writeln("Hello " + name + ".");
document.writeln("It is " + weather + " today");
};
myFunc("Jack", "sunny");
</script>
</body>
</html>
If you define two functions with the same name, the second definition replaces the first.
The number of arguments used in function invoking doesn't need to match the number of parameters in the function.
If you call the function with fewer arguments than it has, the value of parameters you have not supplied values for is undefined. If you call the function with more arguments than there are parameters, the additional arguments are ignored.
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Function:
- Function declaration and calling
- Functions with Parameters
- Function Arguments