# JavaScript Functions

In 
Published 2022-12-03

This tutorial explains to you how you can work with JavaScript functions. JavaScript functions are very used in web development.

Here is a code I have tested for showing how the JavaScript function works:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
</head>

<body>
<script type="text/javascript">
 
        var add100 = function(x) {
            return x+100;
        }
 
        var add1000 = function(x) {
            return x+1000;
        }
 
        function doSomething(var1, function1) {
 
            if (function1 === undefined)
                return var1;
            else
                return function1(var1);
        }
         
        function add200(x) {
            return x+200;
        }
 
        var x1 = doSomething(1);
        alert("x1= "+ x1);
 
        var x2 = doSomething(10, add100 );
        alert("x2= "+ x2);
 
        var x3 = doSomething(1000, add1000);
        alert("x3= "+ x3);
         
        var x4 = add200(x1)
        alert("x4= "+ x4);
 
    </script>
</body>
</html>

And here are the results of the code which use JavaScript functions: