{"id":10222,"date":"2020-08-23T18:55:52","date_gmt":"2020-08-24T01:55:52","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=10222"},"modified":"2023-12-01T03:58:43","modified_gmt":"2023-12-01T11:58:43","slug":"how-to-use-javascript-functions","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/","title":{"rendered":"How to Use JavaScript Functions: A Step-By-Step Guide"},"content":{"rendered":"\n<p><em>JavaScript functions are custom blocks of code that can be reused. Functions allow code to be more modular and are essential to object-oriented programming. Functions can be defined through declarations or expressions. <\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>If you\u2019re trying to learn <a href=\"https:\/\/careerkarma.com\/blog\/javascript-projects\/\">JavaScript<\/a> and looking to know the basics, JS functions are definitely something you need to know. If you have spent any time working with a programming language, you\u2019ll know that functions are the building blocks of complex programs, but you may not know how they work. Functions allow you to write code once for common processes, instead of repeating it multiple times.<br><\/p>\n\n\n\n<p>Functions are blocks of code that perform an action and may return a value. Functions can be customized based on your needs and can be used to make your code more efficient and modular.<br><\/p>\n\n\n\n<p>In this tutorial, we\u2019ll explore the basics of functions: how to define a function, how to call a function, and when they may be useful.<br><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<label for=\"ez-toc-cssicon-toggle-item-69e761041a263\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #000000;color:#000000\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #000000;color:#000000\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e761041a263\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#how-to-use-the-javascript-define-function\" >How to Use the JavaScript Define Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#javascript-function-declarations\" >JavaScript Function Declarations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#javascript-function-expression\" >JavaScript Function Expression<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#function-parameters\" >Function Parameters<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#heres-an-example\" >Here\u2019s an example:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#return-values\" >Return Values<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#arrow-functions\" >Arrow Functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#conclusion\" >Conclusion<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#here-are-some-main-takeaways-from-this-article\" >Here are some main takeaways from this article:<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"how-to-use-the-javascript-define-function\"><\/span><strong>How to Use the JavaScript Define Function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are two ways to define a function in JavaScript: through declarations and expressions. Let\u2019s start with the declaration method of defining a function.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"javascript-function-declarations\"><\/span>JavaScript <strong>Function Declarations<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Function Declarations define a named function. In order to define this type of function, you should start your code with the <code>function<\/code> keyword, followed by the name of the function. Here\u2019s an example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function nameOfYourFunction() {\n\t\/\/ Function code\n}<\/pre><\/div>\n\n\n\n<p>Function names follow the same rules as variables\u2014they can use leers, underscores, numbers, and are often written using camel case. Then, after the variable name, you\u2019ll include a set of parentheses, where optional parameters can be held. We\u2019ll get to those later in the article.<\/p>\n\n\n\n<p>Then, like a for or an if statement, the code of the function will be in curly braces. Here is an example of a function that will print <code>Google<\/code> to the console:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function printGoogle() {\n\tconsole.log(\u201cGoogle\u201d);\n}<\/pre><\/div>\n\n\n\n<p>Within the <code>printGoogle()<\/code> JS function is a <code>console.log()<\/code> statement that will be executed when the function is called. But, nothing will happen until we call the function. If we want to call the function, we can use this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>printGoogle();<\/pre><\/div>\n\n\n\n<p>Now, let\u2019s merge our code together into one function, then invoke it:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/\/ Declare the printGoogle() function\nfunction printGoogle() {\n\tconsole.log(\u201cGoogle\u201d);\n}\n\n\/\/ Invoke the printGoogle() function\nprintGoogle();<\/pre><\/div>\n\n\n\n<p>The output for this function will be <code>Google<\/code>. The <code>printGoogle()<\/code> function will return the result when it is invoked, on the last line in this case.<\/p>\n\n\n\n<p>Now our print code is in a function, we can execute it as many times as we want by calling the <code>printGoogle()<\/code> function.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"javascript-function-expression\"><\/span>JavaScript <strong>Function Expression<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Another way of declaring a function is to create a function expression. We can do so by assigning a function to a variable.<br><\/p>\n\n\n\n<p>Let\u2019s use the same example as above. Rather than declaring the function on its own, we can instead assign it to a variable. Here\u2019s an example:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const google = function printGoogle() {\n\tconsole.log(\u201cGoogle\u201d);\n}<\/pre><\/div>\n\n\n\n<p>In order to call this expression, we add the <code>google()<\/code> line of code to wherever we want the expression to be run.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"function-parameters\"><\/span><strong>Function Parameters<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now we know the two ways in which we can declare a function, we can explore how to customize this feature of programming. In our above code, we have created a function that prints <code>Google<\/code> to the console.<br><\/p>\n\n\n\n<p>In order to print a different name, such as Facebook, we\u2019d need to change the code. If we want users who visit our website to input the name of their favorite company and print it to the console, our function would not work.<br><\/p>\n\n\n\n<p>So, we need to make use of parameters. If we add a <code>name<\/code> parameter to our JS function, then we can print any name to the console through our function. Here\u2019s an example:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function printCompany(name) {\n\tconsole.log(`My favorite company is ${name}!`);\n}<\/pre><\/div>\n\n\n\n<p>The name of the function is <code>printCompany()<\/code> and our parameter is called <code>name<\/code>. The parameter can then be called within the JavaScript function. In the above example, we use the name parameter to change what will be printed on the <code>console.log()<\/code> line of code.<br><\/p>\n\n\n\n<p>But we haven\u2019t defined our name yet. To define the parameter, we need to assign it a value when we call our JavaScript function. Let\u2019s say your favorite company is Snapchat. We\u2019ll call the function and place the company name as an <strong>argument<\/strong> within the function call.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"heres-an-example\"><\/span><strong>Here\u2019s an example:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/\/ Call printCompany() function with \u201cSnapchat\u201d as \u201cname\u201d\nprintCompany(\u201cSnapchat\u201d);<\/pre><\/div>\n\n\n\n<p>When we run this code, the following will be printed:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>My favorite company is Snapchat!<\/pre><\/div>\n\n\n\n<p>In our example, we call the function using <code>printCompany()<\/code>, then we assign the name in parenthesis. So, now we can reuse our function multiple times with different names.<br><\/p>\n\n\n\n<p>It\u2019s worth noting that you can use as many parameters as you want, and you will reference them in order. We\u2019ll use an example showing this in action below.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"return-values\"><\/span><strong>Return Values<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In our examples so far, we have not returned any values. Instead, we have printed some text to the console. But, with a function, we can give it some parameters to process, then return a value based on what\u2019s in the <code>return<\/code> statement.<br><\/p>\n\n\n\n<p>Here\u2019s an example of a function adding two numbers and giving us the total:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function addNumbers(first, second) {\n\treturn first + second;\n}\n\naddNumbers(1, 2);<\/pre><\/div>\n\n\n\n<p>In this program, our function is called and two numbers are passed through the function. When this function is executed\u2014on the final line in our above example\u2014we\u2019ll get the answer <code>3<\/code> in return. Our list of parameters is separated by commas.<br><\/p>\n\n\n\n<p>The program has added 1 and 2, with the parameter names <code>first<\/code> and <code>second<\/code> and returned them to the code. If we want to see these values, we can add a <code>console.log()<\/code> function around the line where we call <code>addNumbers(1, 2)<\/code>.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"arrow-functions\"><\/span><strong>Arrow Functions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>As of ECMAScript 6, there is a more concise way to define functions known as the <a href=\"https:\/\/careerkarma.com\/blog\/javascript-projects\/\">arrow function<\/a>. These are represented by using the following expression: <code>=><\/code>.<br><\/p>\n\n\n\n<p>These functions are a type of function expression. Let\u2019s use an example to showcase arrow functions in action:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const addNumbers = (first, second) =&gt; {\n\treturn first + second;\n}\n\naddNumbers(10, 15);<\/pre><\/div>\n\n\n\n<p>Instead of writing <code>function<\/code>, we can use the arrow sign to denote we are declaring a function. There are a couple of subtle differences between arrow functions and regular functions, but you don\u2019t need to know about those for most use cases.<br><\/p>\n\n\n\n<p>When you\u2019re only working with one variable, you don\u2019t need parentheses around them. And, if you\u2019re not working with any variables, you need to include a set of empty parentheses <code>()<\/code> where your variables would be declared.<\/p>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/repl.it\/@careerkarma\/How-to-use-JavaScript-Functions?lite=true\" width=\"100%\" height=\"400px\" frameborder=\"0\"><\/iframe>\n<br>\n<br>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"666\" src=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/joshua-aragon-FkjaN-7gWC0-unsplash.jpg\" alt=\"\" class=\"wp-image-10224\" srcset=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/joshua-aragon-FkjaN-7gWC0-unsplash.jpg 1000w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/joshua-aragon-FkjaN-7gWC0-unsplash-768x511.jpg 768w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/joshua-aragon-FkjaN-7gWC0-unsplash-770x513.jpg 770w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/joshua-aragon-FkjaN-7gWC0-unsplash-20x13.jpg 20w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/joshua-aragon-FkjaN-7gWC0-unsplash-385x256.jpg 385w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption><em>Learning to use JavaScript functions will significantly advance your coding abilities.<\/em><\/figcaption><\/figure>\n\n\n\n<p>That\u2019s all you need to know about the basics of functions. In this tutorial, we\u2019ve covered function declarations, function expressions, returning values from functions, and arrow functions.<br><\/p>\n\n\n\n<p>Overall, a function is a block of code that can perform an action and return a variable. Functions are useful if you have multiple lines of code that you may need to execute many times throughout a program.<br><\/p>\n\n\n\n<p>Instead of writing those multiple lines of code every time you need to use them, you can add them to a function and call the function when you need to run the code, and pass the values you need to use into your function.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"here-are-some-main-takeaways-from-this-article\"><\/span><strong>Here are some main takeaways from this article:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Functions are subprograms designed to run certain lines of code.<\/li><li>Functions are only executed when they are called. We call this invoking a function.<\/li><li>Values can be passed into functions, then used within the function.<\/li><li>Functions can return values.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"JavaScript functions are custom blocks of code that can be reused. Functions allow code to be more modular and are essential to object-oriented programming. Functions can be defined through declarations or expressions. If you\u2019re trying to learn JavaScript and looking to know the basics, JS functions are definitely something you need to know. If you&hellip;","protected":false},"author":240,"featured_media":2578,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[12687],"class_list":{"0":"post-10222","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript","8":"tag-tutorial"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":[]},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use Functions in JavaScript | Career Karma<\/title>\n<meta name=\"description\" content=\"Functions are an important part of coding with JavaScript. Learn how to identify and use JavaScript functions in this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use JavaScript Functions: A Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Functions are an important part of coding with JavaScript. Learn how to identify and use JavaScript functions in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-24T01:55:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:58:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/christopher-robin-ebbinghaus-681475-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"How to Use JavaScript Functions: A Step-By-Step Guide\",\"datePublished\":\"2020-08-24T01:55:52+00:00\",\"dateModified\":\"2023-12-01T11:58:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/\"},\"wordCount\":1200,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/christopher-robin-ebbinghaus-681475-unsplash.jpg\",\"keywords\":[\"tutorial\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/\",\"name\":\"How to Use Functions in JavaScript | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/christopher-robin-ebbinghaus-681475-unsplash.jpg\",\"datePublished\":\"2020-08-24T01:55:52+00:00\",\"dateModified\":\"2023-12-01T11:58:43+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Functions are an important part of coding with JavaScript. Learn how to identify and use JavaScript functions in this article.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/christopher-robin-ebbinghaus-681475-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/christopher-robin-ebbinghaus-681475-unsplash.jpg\",\"width\":1200,\"height\":800,\"caption\":\"\\\"Programming language illustration\u201d\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/how-to-use-javascript-functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Use JavaScript Functions: A Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use Functions in JavaScript | Career Karma","description":"Functions are an important part of coding with JavaScript. Learn how to identify and use JavaScript functions in this article.","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:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/","og_locale":"en_US","og_type":"article","og_title":"How to Use JavaScript Functions: A Step-By-Step Guide","og_description":"Functions are an important part of coding with JavaScript. Learn how to identify and use JavaScript functions in this article.","og_url":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-24T01:55:52+00:00","article_modified_time":"2023-12-01T11:58:43+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/christopher-robin-ebbinghaus-681475-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"How to Use JavaScript Functions: A Step-By-Step Guide","datePublished":"2020-08-24T01:55:52+00:00","dateModified":"2023-12-01T11:58:43+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/"},"wordCount":1200,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/christopher-robin-ebbinghaus-681475-unsplash.jpg","keywords":["tutorial"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/","url":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/","name":"How to Use Functions in JavaScript | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/christopher-robin-ebbinghaus-681475-unsplash.jpg","datePublished":"2020-08-24T01:55:52+00:00","dateModified":"2023-12-01T11:58:43+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Functions are an important part of coding with JavaScript. Learn how to identify and use JavaScript functions in this article.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/christopher-robin-ebbinghaus-681475-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/christopher-robin-ebbinghaus-681475-unsplash.jpg","width":1200,"height":800,"caption":"\"Programming language illustration\u201d"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"How to Use JavaScript Functions: A Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/10222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=10222"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/10222\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/2578"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=10222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=10222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=10222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}