What is functions in javascript?

Posted by

A function is a set of statements that take inputs, do some specific computation, and produce output. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs

Syntax

function functionName(Parameter1, Parameter2, ..)
{
    // Function body
}

example

<!DOCTYPE html>
<html>
<head>
		<title> alert in javascript</title>
</head>
<body>
		<script>
		function f1()
		{
		document.write("this is function");
		document.write("<br>");
		document.write("in javascript");
		
		}
		function f2()
		{
		document.write("using multiple ");
		document.write("function");
		}
		
		f1();
		document.write("<br>");
		f2();
		</script>

</body>
</html>

output

this is function
in javascript
using multiple function
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x