{"id":1474,"date":"2016-07-21T08:18:37","date_gmt":"2016-07-21T08:18:37","guid":{"rendered":"http:\/\/javascript-tutor.net\/?p=1474"},"modified":"2017-09-21T13:34:46","modified_gmt":"2017-09-21T13:34:46","slug":"adding-arguments-function","status":"publish","type":"post","link":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/","title":{"rendered":"Adding arguments to a JavaScript function"},"content":{"rendered":"<p>You can create a function in JavaScript and add arguments to it. An argument is one or more variables that are declared within the parenthesis of a function definition. The syntax is<\/p>\n<p>function \u00a0MyFunction(x,y,z)<\/p>\n<p>{ \u00a0statements;}<\/p>\n<p>You can also use the return keyword to return a value to the statement.<\/p>\n<p>function \u00a0MyFunction(x,y,z)<\/p>\n<p>{ \u00a0return value;\u00a0}<\/p>\n<p>Example:<\/p>\n<p>function Area_Rect(width,length)<\/p>\n<p>{ area=width*length;<\/p>\n<p>return area;}<\/p>\n<p>You can call the function by assigning values to the arguments, such as<\/p>\n<p>document.write(Area_Rect(4,6));<\/p>\n<p>0r alert (&#8220;The area of a rectangle is&#8221;+Area_Rect(4,6)<\/p>\n<p>The area of the rectangle if width=4 and length=6 is:<br \/>\n<script>\/\/ <![CDATA[\nfunction Area_Rect(width,length) { area=width*length; return area;} document.write(\"The area of the rectangle is \"+Area_Rect(4,6));\n\/\/ ]]><\/script><\/p>\n<p>Please follow <a href=\"http:\/\/javascript-tutor.net\/index.php\/lesson-13-function-part-1-introduction\/\">Lesson 13<\/a>\u00a0and <a href=\"http:\/\/javascript-tutor.net\/index.php\/lesson-14-function-part-2-more-examples\/\">Lesson 14<\/a> to learn more about function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can create a function in JavaScript and add arguments to it. An argument is one or more variables that are declared within the parenthesis of a function definition. The syntax is function \u00a0MyFunction(x,y,z) { \u00a0statements;} You can also use the return keyword to return a value to the statement. function \u00a0MyFunction(x,y,z) { \u00a0return value;\u00a0} &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding arguments to a JavaScript function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1474","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Adding arguments to a JavaScript function - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"description\" content=\"Learn how to add arguments to a JavaScript function\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding arguments to a JavaScript function - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"Learn how to add arguments to a JavaScript function\" \/>\n<meta property=\"og:url\" content=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-21T08:18:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-09-21T13:34:46+00:00\" \/>\n<meta name=\"author\" content=\"Liew Voon Kiong\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liew Voon Kiong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/\",\"url\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/\",\"name\":\"Adding arguments to a JavaScript function - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2016-07-21T08:18:37+00:00\",\"dateModified\":\"2017-09-21T13:34:46+00:00\",\"author\":{\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\"},\"description\":\"Learn how to add arguments to a JavaScript function\",\"breadcrumb\":{\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding arguments to a JavaScript function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\",\"name\":\"Liew Voon Kiong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"caption\":\"Liew Voon Kiong\"},\"url\":\"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding arguments to a JavaScript function - Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Learn how to add arguments to a JavaScript function","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:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/","og_locale":"en_US","og_type":"article","og_title":"Adding arguments to a JavaScript function - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"Learn how to add arguments to a JavaScript function","og_url":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_published_time":"2016-07-21T08:18:37+00:00","article_modified_time":"2017-09-21T13:34:46+00:00","author":"Liew Voon Kiong","twitter_misc":{"Written by":"Liew Voon Kiong","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/","url":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/","name":"Adding arguments to a JavaScript function - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2016-07-21T08:18:37+00:00","dateModified":"2017-09-21T13:34:46+00:00","author":{"@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8"},"description":"Learn how to add arguments to a JavaScript function","breadcrumb":{"@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/21\/adding-arguments-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"Adding arguments to a JavaScript function"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8","name":"Liew Voon Kiong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","caption":"Liew Voon Kiong"},"url":"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=1474"}],"version-history":[{"count":10,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1474\/revisions"}],"predecessor-version":[{"id":1509,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1474\/revisions\/1509"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}