JavaScript Function – How to write a function in JavaScript?

In this guide, we will learn How to write a function in JavaScript in programming for javascript function. The guide includes an example of a function with easy to understand written code. You can join us on social networks using Facebook sign up to get the latest updates from us like function definition in maths code or solving functions examples.

Let’s have a look on what is Javascript function and how it writes?

JavaScript Function

A Block of code that is designed to perform a specific task is known as JavaScript Function. And the function is executed when it is called.

Syntax:

function name( parar1, parar2, parar3)
{
// code to be run.
}

Example:

<!DOCTYPE html>
<html>
<body>
<h2>Functions</h2>
<p>In below example,function is called to complete a calculation:</p>
<p id="darkweb"></p>
<script>
function myhelloFunction(Ns1, Ns2) {
  return Ns1 * Ns2;
}
document.getElementById("darweb").innerHTML = myhelloFunction(5, 6);
</script>
</body>
</html>

Return Function In JavaScript

In JavaScript the return statement , the function will stop execution.

If the function was called from the statement then the JavaScript will return to execute the code after the statement is called.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>Functions</h2>
<p>In below example,function is called to run a calculation:</p>
<p id="darkweb"></p>
<script>
function myhelloFunction(Ns1, Ns2) {
  return Ns1 * Ns2;
}
document.getElementById("darkweb").innerHTML = myhelloFunction(54, 64);
</script>
</body>
</html>

find more tutorial of javascript and join us to get more development tutorial to increase your knowladge.

Stay in touch. Ask Questions.
Lean on us for help, strategies and expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *