Use same name for different functions in JavaScript

Description

The following code shows how to use same name for different functions.

Example


<!--from   w w  w .  ja  v  a 2 s  .  co m-->


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var addSomeNumber = function (num){
return num + 100;
};

addSomeNumber = function (num) {
return num + 200;
};

var result = addSomeNumber(100); //300
document.writeln(result);

</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use same name for different functions in JavaScript