Write a function in JavaScript

In this tutorial, we will learn how to write a function in JavaScript.

Functions:

  • JavaScript functions perform the simplest task.
  • They allow a set of instructions to execute them whenever needed.
  • The JavaScript Functions are understandable for everyone.
  • They give simple execution.
  • Functions give the easiest way to declare variables and expressions.
  • Functions give the Return Statement also.

 

JavaScipt Funtion Example:

<html>
<head>
<meta charset=utf-8 />
<title>JavaScript Functions</title>
<script>
function msg(lastName) {
    function welcome() {
        console.log("Welcome " + lastName);
    }

    return welcome;
}


var greet= msg("Pendyala");


greet(); 
</script>
</head>
<body>
</body>
</html>

output:

Welcome Pendyala

Leave a Comment

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

Scroll to Top