{"id":3162,"date":"2023-02-15T10:33:53","date_gmt":"2023-02-15T15:33:53","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=3162"},"modified":"2023-02-15T10:33:53","modified_gmt":"2023-02-15T15:33:53","slug":"functions-in-javascript","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/02\/15\/functions-in-javascript\/","title":{"rendered":"Functions in JavaScript"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3163\" src=\"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/02\/javascript-function-with-parameter-300x125.png\" alt=\"\" width=\"300\" height=\"125\" srcset=\"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/02\/javascript-function-with-parameter-300x125.png 300w, https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/02\/javascript-function-with-parameter-768x320.png 768w, https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/02\/javascript-function-with-parameter.png 806w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><strong> Functions in JavaScript<\/strong><\/p>\n<p>In JavaScript, functions are essentially pieces of reusable code that are designed to perform a task when called, or executed. Functions have inputs and outputs, much like those that you typically think of in a mathematical context. Functions have parameters that they take &#8211; in the above photo,<strong> name<\/strong> is a parameter of the function <strong>greet<\/strong>. Functions also have code that the execute. The above photo only has\u00a0<strong>\/\/ code<\/strong> commented, not giving us an example of what code this function might execute, but we can make up the example that this function might execute <strong>{console.log(&#8220;hello, &#8221; + name);}<\/strong>. Then, when you call the function, or tell the computer to run the action, our code would execute. Of course, our variable\u00a0<strong>name<\/strong> would have to be previously defined &#8211; for the ease of the example, we can say we defined <strong>let name = &#8220;John&#8221;<\/strong>. Without knowing how the\u00a0<strong>greet<\/strong> function actually executes, we can say in this example that when we call <strong>greet(&#8220;John&#8221;)<\/strong> that our function would return\u00a0<strong>hello, John<\/strong>. Functions can become much more complicated depending on the parameters, the functions that you&#8217;re actually using, and the statements or code inside the function that the function will execute, but the basic idea behind a function is still inputs and outputs!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Functions in JavaScript In JavaScript, functions are essentially pieces of reusable code that are designed to perform a task when called, or executed. Functions have inputs and outputs, much like those that you typically think of in a mathematical context. Functions have parameters that they take &#8211; in the above photo, name is a parameter [&hellip;]<\/p>\n","protected":false},"author":29393,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[663943],"tags":[],"class_list":{"0":"post-3162","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-instructor","7":"entry"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/users\/29393"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=3162"}],"version-history":[{"count":1,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3162\/revisions"}],"predecessor-version":[{"id":3164,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3162\/revisions\/3164"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=3162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=3162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=3162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}