Home >>Javascript Programs >Create functions with default arguments in JavaScript

Create functions with default arguments in JavaScript

How to Create functions with default arguments in JavaScript

In this article we will learn and write how to create functions with default arguments in JavaScript. In JavaScript, you can pass a number of parameters during the function call. The arguments are the variables that are local to function and take values from the parameters. There are two important things in JavaScript function name and parameters and arguments.

Let's take an example:

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunc2()">Click me</button>
<script>
function myFunc2(a=5, b=12) {
	var x = document.write(a+b);
	return x;
}
</script>
</body>
</html>
Output:


No Sidebar ads