

{"id":51858,"date":"2019-03-18T11:46:29","date_gmt":"2019-03-18T06:16:29","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=51858"},"modified":"2019-08-05T11:10:28","modified_gmt":"2019-08-05T05:40:28","slug":"javascript-function","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/javascript-function\/","title":{"rendered":"JavaScript Functions &#8211; Concept to Ease your Web Development Journey"},"content":{"rendered":"<p>Functions are one of the major pillars of JavaScript.\u00a0Basically, a JavaScript function is a set of statements that performs some tasks or do some computation and then returns the result to the user<em>.\u00a0<\/em>Today in this JavaScript tutorial we will cover the fundamentals of JavaScript Functions.<\/p>\n<p>We will understand what functions are, how to define and use them, and various other terminologies associated with them. Also, we will take a brief look at the function scope and learn a bit about JavaScript\u2019s built-in functions available to the programmers.<\/p>\n<p><em><strong>Before starting we would recommend you to take a quick revision on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-loop-control\/\">JavaScript Loop Control<\/a>.\u00a0<\/strong><\/em><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65970\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1.jpg\" alt=\"JavaScript Functions (1)\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Functions-1-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<h2>What are JavaScript Functions?<\/h2>\n<p>A JavaScript function is a procedure or a subprogram, i.e., a block of code that performs a certain task. It is a group of reusable code that you can use anywhere in the code. It helps you to divide a large program into small and manageable functions. With the help of functions, you don\u2019t need to write the same block of code repeatedly. This makes a program a lot more efficient and reduces the code length.<\/p>\n<p>We used some functions like <strong>prompt()<\/strong> and<strong> write()<\/strong> in our previous JavaScript Tutorials of this series. These are the built-in functions that JavaScript provides, and you will learn more about them later in this tutorial. For now, let\u2019s move onto the syntax of a JavaScript function.<\/p>\n<h3>Function Definition<\/h3>\n<p>A function definition (also called a function statement or a function declaration) includes a function keyword, with its syntax as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">function functionName(parameters)\r\n{\r\n  \/\/statements\r\n}<\/pre>\n<p>It is important to separate the parameters with commas.<\/p>\n<h3>Return Statement<\/h3>\n<p>This is an optional JavaScript statement that returns a value from the function. Unless specified otherwise, a function returns undefined. We use the keyword return, followed by the statement or expression we want to return. This statement should be the last one in the block because it skips all code in the block written after that. We will make use of this statement in the section of Calling Function.<\/p>\n<p>The basic syntax of a return statement is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">return value;<\/pre>\n<h3>Function Expressions<\/h3>\n<p>The function declaration above is syntactically a statement. We can also create a function using a function expression. These functions can be anonymous, i.e., they don\u2019t have any name. This is one of the features we learned about in our article on<em><strong> <a href=\"https:\/\/data-flair.training\/blogs\/javascript-tutorial\/\">Introduction to JavaScript<\/a>.<\/strong><\/em> The syntax for these expressions is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">variable = function (parameters){ \/\/expression };<\/pre>\n<h3>Calling Functions<\/h3>\n<p>A defined function doesn\u2019t execute automatically. A function definition only specifies what to do when we execute the function. The actual execution is possible with the help of function invocation or function call. Functions must be in their scope when called and when we are using function expressions in our code. This is because function declarations support hoisting, but function expressions don\u2019t.<\/p>\n<p>The syntax for function invocation is like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">functionName(arguments);<\/pre>\n<p>Like parameters, we separate arguments of a function call with the use of commas.<\/p>\n<p>We are now going to wrap up all we\u2019ve learned so far in two JavaScript programs, one with function declaration and the other with function expression.<\/p>\n<p><strong>Using function declaration:<\/strong><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      function saySomething(){ \/\/function definition\r\n        alert(\"Hello DataFlair!\"); \/\/create an alert in browser\r\n      }\r\n      document.write(\"Return Type: \" + saySomething()); \/\/calling function and returning type\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Screenshot &#8211;<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66125 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function.jpg\" alt=\"calling function in JS\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66126 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op.jpg\" alt=\"JS calling function op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-calling-function-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Using function expression:<\/strong><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var area = function(height, weight){ \/\/function expression\r\n        return height * weight; \/\/returning area of rectangle\r\n      }\r\n      document.write(\"DataFlair: Using functions&lt;\/br&gt;\");\r\n\r\n      document.write(\"Area of the rectangle is \" + area(4, 9)); \/\/calling function by passing parameters\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><b>Screenshot-<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66131 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression.jpg\" alt=\"using js function expression\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output &#8211;<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66132\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op.jpg\" alt=\"using JavaScript function expression op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/using-JavaScript-function-expression-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>Function Parameters and Arguments<\/h3>\n<p>When you begin programming, you often hear the terms: arguments and parameters. Many programmers get confused with these terms, but it is crucial that you understand what they are and how are they different from each other.<\/p>\n<p><strong>Parameters<\/strong> are used inside the parenthesis in a function declaration. It takes whatever value the function arguments contain and work with them for the entirety of the function. The lifetime of parameters is only inside the function. You cannot access or modify them from outside the function. In a function definition, we can pass up to 255 parameters, separated by commas.<\/p>\n<p>On the other hand,<strong> arguments<\/strong> are the actual values that we pass to a function at the time of function call. The names of an argument or parameter can be the same or different, as per your convenience. But you need to make sure that the numbers of arguments and parameters for a function are the same.<\/p>\n<p>In the above program, <strong>height<\/strong> and <strong>weight<\/strong> are parameters, while <strong>4<\/strong> and <strong>9<\/strong> are the arguments. <strong>height<\/strong> and <strong>weight<\/strong> take on the value of <strong>4<\/strong> and <strong>9<\/strong> respectively in this case.<\/p>\n<h3>Function Scope<\/h3>\n<p>A variable defined inside a function cannot be accessed outside it. But a function can access any variable defined as a global variable. When you define a function inside another function, we call that a nested function. This function is the child function of whichever function it is defined in <em>(the parent function)<\/em>. A child function has access to all the variables defined in the parent function or which the parent has access to; vice-versa is not true.<\/p>\n<p><em><strong>Didn&#8217;t you check DataFlair&#8217;s latest tutorial on<a href=\"https:\/\/data-flair.training\/blogs\/javascript-variable-tutorial\/\"> JavaScript Variables<\/a>?<\/strong><\/em><\/p>\n<p>Too much theory? Get ready to understand exactly what I mean with the following code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n    &lt;h3&gt;DataFlair: Function Scope&lt;\/h3&gt;\r\n\r\n    &lt;script&gt;\r\n      var num1 = 2;\r\n      document.write(\"Value of number 1 is \" + num1 + \". (Global scope)&lt;\/br&gt;\");\r\n      function parentFunction(){ \/\/global function\r\n        var num2 = 4;\r\n        num1 = 8;\r\n        document.write(\"Value of number 1 is \" + num1 + \". (Inside global function)&lt;\/br&gt;\");\r\n        document.write(\"Value of number 2 is \" + num2 + \". (Inside parent function)&lt;\/br&gt;\");\r\n        childFunction(); \/\/child function called\r\n        document.write(\"Value of number 3 is \" + num3 + \". (Inside parent function)&lt;\/br&gt;\");\r\n\r\n        function childFunction(){ \/\/nested function\r\n          var num3 = 0;\r\n          document.write(\"Value of number 2 is \" + num2 + \". (Inside child function)&lt;\/br&gt;\");\r\n          document.write(\"Value of number 3 is \" + num3 + \". (Local scope)&lt;\/br&gt;\");\r\n        }\r\n      }\r\n      parentFunction(); \/\/parent function called\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p><b>Screenshot &#8211;<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66134 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1.jpg\" alt=\"function scope in JS\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66135\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op.jpg\" alt=\"function scope1 op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope1-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Now try the same code again; this time remove the comment from the write function above.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n    &lt;h3&gt;DataFlair: Function Scope&lt;\/h3&gt;\r\n\r\n    &lt;script&gt;\r\n      var num1 = 2;\r\n      document.write(\"Value of number 1 is \" + num1 + \". (Global scope)&lt;\/br&gt;\");\r\n      function parentFunction(){ \/\/global function\r\n        var num2 = 4;\r\n        num1 = 8;\r\n        document.write(\"Value of number 1 is \" + num1 + \". (Inside global function)&lt;\/br&gt;\");\r\n        document.write(\"Value of number 2 is \" + num2 + \". (Inside parent function)&lt;\/br&gt;\");\r\n        childFunction(); \/\/child function called\r\n        \/\/document.write(\"Value of number 3 is \" + num3 + \". (Inside parent function)&lt;\/br&gt;\");\r\n\r\n        function childFunction(){ \/\/nested function\r\n          var num3 = 0;\r\n          document.write(\"Value of number 2 is \" + num2 + \". (Inside child function)&lt;\/br&gt;\");\r\n          document.write(\"Value of number 3 is \" + num3 + \". (Local scope)&lt;\/br&gt;\");\r\n        }\r\n      }\r\n      parentFunction(); \/\/parent function called\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><b>Screenshot &#8211;<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66137\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2.jpg\" alt=\"function scope2\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66138\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op.jpg\" alt=\"function scope2 op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/function-scope2-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Note that in both cases, the browser displays the same output. The difference is that when you run your code the second time, you get an error. You wanted to print the value of <strong>num3<\/strong> at last, but that line is missing. This is because <strong>parentFunction<\/strong> tried to access a local variable of its child i.e. <strong>childFunction.<\/strong><\/p>\n<h2>Types of JavaScript Functions<\/h2>\n<h3>1. Recursive Functions<\/h3>\n<p>It is possible for a function to call itself directly or indirectly. A function that calls itself during its execution is a recursive function. This allows a function to repeat for multiple iterations, minimizing the code. The problem with these functions is that, if not written properly, they can cause <strong>infinite loops<\/strong> and other unexpected results.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Recursive-Function.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66201\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Recursive-Function.png\" alt=\"Recursive Function in JavaScript\" width=\"552\" height=\"694\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Recursive-Function.png 552w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Recursive-Function-119x150.png 119w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Recursive-Function-239x300.png 239w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Recursive-Function-520x654.png 520w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/a><\/p>\n<p>Let\u2019s understand these functions a little better with the help of a JavaScript code to find the factorial of a number. The flowchart below depicts the algorithm for calculating the factorial of a number.<\/p>\n<p><em><strong>Do you know how to construct <a href=\"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/\">loops in JavaScript<\/a>?<\/strong><\/em><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n&lt;body&gt;\r\n  &lt;h3&gt;DataFlair: Recursive function&lt;\/h3&gt;\r\n\r\n    &lt;script&gt;\r\n      let fact = 1, num = 5; \/\/initializing variables\r\n      function calculateFactorial(number){ \/\/function definition\r\n        if(number == 0)\r\n          return 1; \/\/ 0! = 1\r\n        else\r\n          return number * calculateFactorial(number - 1); \/\/recursion: calling itself\r\n      }\r\n      document.write(\"The factorial of \" + num + \" is \" + calculateFactorial(num)); \/\/function called with an argument\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p><b>Screenshot &#8211;<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66141 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function.jpg\" alt=\"JS recursive function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output &#8211;<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66142\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op.jpg\" alt=\"JavaScript recursive function op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-recursive-function-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>2. Arrow Functions<\/h3>\n<p>An arrow function, introduced with ECMAScript 2015, is a compact way to write JavaScript functions. They have shorter syntax than function expressions and doesn\u2019t work with <strong>this<\/strong> keyword. These functions are always anonymous i.e., they have no names. This is why we don\u2019t use them as methods, and the reason we cannot use them as constructors.<\/p>\n<p>These functions use the <strong>=&gt; arrow<\/strong> to declare a function rather than the <strong>function<\/strong> keyword.<br \/>\nLet\u2019s see with an example of how these functions reduce the code length by comparing it with a normal function.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      function hello(str){ \/\/function declaration\r\n        return \"Hello \" + str;\r\n      }\r\n      document.write(\"By a regular function:&lt;\/br&gt;\");\r\n      document.write(hello(\"DataFlair&lt;\/br&gt;&lt;\/br&gt;\")); \/\/function call\r\n\r\n      var helloAgain = str =&gt; \"Hello \" + str; \/\/arrow function\r\n\r\n      document.write(\"By an arrow function:&lt;\/br&gt;\");\r\n      document.write(helloAgain(\"DataFlair\")); \/\/function call\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p><strong>Screenshot &#8211;<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66203\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript.jpg\" alt=\"JavaScript arrow Function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/arrow-function-in-Javascript-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-66146\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop.jpg\" alt=\"JavaScript arrow functionop\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-arrow-functionop-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>These functions are usually helpful in large-scale projects. Using these functions in the program helps programmers to optimize their code. Practice these functions as much as you can to gain mastery over them.<\/p>\n<p>All the functions we discussed above were the ones you defined. What if we don\u2019t want to do that? Is there a way to use predefined codes to save you time and money? The answer to that question is yes, with the help of JavaScript built-in methods. Methods are nothing, but functions associated with a <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/javascript-objects\/\">JavaScript object.<\/a><\/strong><\/em><\/p>\n<h3>3. Built-in Methods<\/h3>\n<p>JavaScript provides various built-in methods for programmers to use directly. The JavaScript interpreter understands these methods without you having to define them. You can call these methods anywhere in your program directly. It is not possible to know all the built-in methods in a single tutorial. You will learn their use as you code more in JavaScript. Some of the most common built-in functions of JavaScript are as follows:<\/p>\n<ul>\n<li>\n<h4>alert()<\/h4>\n<\/li>\n<\/ul>\n<p>This method displays text in a dialog box that pops up on the screen. These are generally used to convey some information or a warning to the user before loading the page on the browser.<\/p>\n<ul>\n<li>\n<h4>prompt()<\/h4>\n<\/li>\n<\/ul>\n<p>Like alert(), the prompt() method also displays text in a dialog box on the screen. But this method provides the user with the facility to enter some data as well.<\/p>\n<ul>\n<li>\n<h4>write()<\/h4>\n<\/li>\n<\/ul>\n<p>This JavaScript method is very useful when you want to print something on your desktop using <a href=\"https:\/\/en.wikipedia.org\/wiki\/JavaScript\">JavaScript<\/a> only. It helps programmers in dynamic programming since it prints the content on the browser only when an event occurs.<\/p>\n<ul>\n<li>\n<h4>getElementById()<\/h4>\n<\/li>\n<\/ul>\n<p>This method returns the element whose ID you passed in the function as an argument. If the ID passed to the function doesn\u2019t exist, it returns null.<\/p>\n<ul>\n<li>\n<h4>getElementsByClassName()<\/h4>\n<\/li>\n<\/ul>\n<p>This JavaScript method returns a collection of all the elements in the document that have the same class name as the argument. This collection is the collection of nodes, returned as a JavaScript NodeList. You can access each node by its index number (starting with 0). These are explained in further detail in DataFlair\u2019s <em><strong>JavaScript Tutorial on Document Object Model.<\/strong><\/em><\/p>\n<ul>\n<li>\n<h4>getDate()<\/h4>\n<\/li>\n<\/ul>\n<p>This JavaScript method provides special functionality to our program. It returns the current date returned by the device. This method is always used with a Date object. You will learn more about this object and other methods associated with it in our tutorial on <em><strong>J<\/strong><strong>avaScript Date and Time<\/strong><\/em>.<\/p>\n<ul>\n<li>\n<h4>includes()<\/h4>\n<\/li>\n<\/ul>\n<p>This method checks a collection for a specific string that we want to find. Based on whether or not the string is a part of that collection, it returns true or false. Remember, this method is case sensitive; you need to be careful about what you pass as an argument.<\/p>\n<h2>Summary<\/h2>\n<p>With this, we come to the end of our tutorial on JavaScript Functions. With the help of function keyword, we can define JavaScript function. A function can include one or more parameters. It is optional to specify functions parameter values while executing it. In this article, we covered various topics related to JavaScript functions. I want you to practice these codes, as much as you can. You will be an expert on JavaScript functions as you continue programming in JavaScript.<\/p>\n<p><em><strong>Now, you must go through our next article on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-class\/\">JavaScript Class<\/a><\/strong><\/em><\/p>\n<p>If there is something which we missed, please let us know through comments. Waiting for your valuable feedback.<\/p>\n<p><strong>Happy Learning!<\/strong><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1454,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/JavaScript&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251208180004\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/JavaScript&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 07:25:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 10:12:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-19 20:12:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-23 14:26:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-26 20:33:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-30 03:46:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 10:04:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-08 07:59:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-11 13:08:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-16 08:13:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-20 13:51:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-24 03:23:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-28 01:26:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-31 06:28:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-03 10:56:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 05:25:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 14:40:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 17:27:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 11:10:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 10:59:31&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-02 23:12:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-07 09:23:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-16 15:08:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 11:51:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-26 05:27:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-01 15:53:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 04:38:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 05:37:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-14 10:47:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-17 11:57:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-21 02:42:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 09:17:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-28 02:46:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-01 07:17:08&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-05-05 18:21:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-11 11:12:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-14 16:04:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-17 16:56:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-21 17:58:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 08:21:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-30 04:19:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-02 22:21:06&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-06 18:08:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-11 08:17:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-15 08:00:22&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-15 08:00:22&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Functions are one of the major pillars of JavaScript.\u00a0Basically, a JavaScript function is a set of statements that performs some tasks or do some computation and then returns the result to the user.\u00a0Today in&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":51924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18979],"tags":[20776,20777,19011,20775,20778],"class_list":["post-51858","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-arrow-methods","tag-built-in-methods","tag-javascript-functions","tag-recursive-functions-in-js","tag-what-is-javascript-function"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript Functions - Concept to Ease your Web Development Journey - DataFlair<\/title>\n<meta name=\"description\" content=\"JavaScript function is a block of code that performs some tasks &amp; it divides a large program into small function, learn recursive,built-in,&amp; arrow functions\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/javascript-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Functions - Concept to Ease your Web Development Journey - DataFlair\" \/>\n<meta property=\"og:description\" content=\"JavaScript function is a block of code that performs some tasks &amp; it divides a large program into small function, learn recursive,built-in,&amp; arrow functions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/javascript-function\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-18T06:16:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-08-05T05:40:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/03\/JavaScript-function-tutorial.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Functions - Concept to Ease your Web Development Journey - DataFlair","description":"JavaScript function is a block of code that performs some tasks & it divides a large program into small function, learn recursive,built-in,& arrow functions","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/javascript-function\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Functions - Concept to Ease your Web Development Journey - DataFlair","og_description":"JavaScript function is a block of code that performs some tasks & it divides a large program into small function, learn recursive,built-in,& arrow functions","og_url":"https:\/\/data-flair.training\/blogs\/javascript-function\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-03-18T06:16:29+00:00","article_modified_time":"2019-08-05T05:40:28+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/03\/JavaScript-function-tutorial.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"JavaScript Functions &#8211; Concept to Ease your Web Development Journey","datePublished":"2019-03-18T06:16:29+00:00","dateModified":"2019-08-05T05:40:28+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/"},"wordCount":1696,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/03\/JavaScript-function-tutorial.jpg","keywords":["Arrow methods","built-in methods","JavaScript Functions","Recursive functions in JS","what is JavaScript function"],"articleSection":["JavaScript Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/javascript-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/","url":"https:\/\/data-flair.training\/blogs\/javascript-function\/","name":"JavaScript Functions - Concept to Ease your Web Development Journey - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/03\/JavaScript-function-tutorial.jpg","datePublished":"2019-03-18T06:16:29+00:00","dateModified":"2019-08-05T05:40:28+00:00","description":"JavaScript function is a block of code that performs some tasks & it divides a large program into small function, learn recursive,built-in,& arrow functions","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/javascript-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/03\/JavaScript-function-tutorial.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/03\/JavaScript-function-tutorial.jpg","width":1200,"height":628,"caption":"Introduction to JavaScript Function"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/javascript-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JavaScript Tutorial","item":"https:\/\/data-flair.training\/blogs\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Functions &#8211; Concept to Ease your Web Development Journey"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/51858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=51858"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/51858\/revisions"}],"predecessor-version":[{"id":66844,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/51858\/revisions\/66844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/51924"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=51858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=51858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=51858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}