{"id":2589,"date":"2022-05-13T15:18:29","date_gmt":"2022-05-13T12:18:29","guid":{"rendered":"https:\/\/www.etemkeskin.com\/?p=2589"},"modified":"2022-05-13T15:25:10","modified_gmt":"2022-05-13T12:25:10","slug":"currying-at-javascript","status":"publish","type":"post","link":"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/","title":{"rendered":"Currying at Javascript"},"content":{"rendered":"\n<p><strong>Currying<\/strong> is an important technique in functional programming. It is asked as an interview question in many interviews.<\/p>\n\n\n\n<p><strong>Currying<\/strong> technique is the process of transforming a function so that it is called with a single parameter like <strong>f(a)(b)(c)<\/strong> each time, instead of calling it to take multiple parameters as in <strong>f(a, b, c)<\/strong>.<\/p>\n\n\n\n<p>Let&#8217;s take a simple look at the following example.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}\">function sum(a,b,c) {\n    return a + b + c;\n};\nsum(5, 10, 15);<\/pre><\/div>\n\n\n\n<p>Let&#8217;s write the <strong>sum()<\/strong> function with the currying technique.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const sum = (a) =&gt; {\n    return (b) =&gt; {\n        return (c) =&gt; {\n            return a + b + c\n        }\n    }\n}\nsum(5)(10)(15);<\/pre><\/div>\n\n\n\n<p>As you can see, every time we call the function we just wrote, a new function returns.<\/p>\n\n\n\n<p>In order to understand the <strong>Currying <\/strong>concept well, it is necessary to know the concept of <strong>Closure<\/strong> in javascript.<\/p>\n\n\n\n<h3>Advantages<\/h3>\n\n\n\n<ol><li>By calling the same function partially, we ensure that different results are returned in different parts of the project.<\/li><li>We prevent code duplication.<\/li><li>We avoid entering the same parameter repeatedly.<\/li><\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const logs = (logType) =&gt; {\n  return (logDate) =&gt; {\n    console.log(`${logType} : there was an issue on ${logDate}.`);\n  };\n};\n\nconst logDate = logs('Warning');\n\/\/1. Log Message\nlogDate(new Date());\n\/\/2. Log Message\nlogDate(new Date());<\/pre><\/div>\n\n\n\n<p>Good Luck&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Currying is an important technique in functional programming. It is asked as an interview question in many interviews. Currying technique is the process of transforming a function so that it is called with a single parameter like f(a)(b)(c) each time, instead of calling it to take multiple parameters as in f(a, b, c). Let&#8217;s take [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,50],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Currying at Javascript - blog website<\/title>\n<meta name=\"description\" content=\"Currying is an important technique in functional programming. It is asked as an interview question in many interviews.Currying technique is the process of transforming a function so that it is called with a single parameter like f(a)(b)(c) each time, instead of calling it to take multiple parameters as in f(a, b, c).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"tr_TR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Currying at Javascript - blog website\" \/>\n<meta property=\"og:description\" content=\"Currying is an important technique in functional programming. It is asked as an interview question in many interviews.Currying technique is the process of transforming a function so that it is called with a single parameter like f(a)(b)(c) each time, instead of calling it to take multiple parameters as in f(a, b, c).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"blog website\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-13T12:18:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-13T12:25:10+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tahmini okuma s\u00fcresi\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 dakika\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.etemkeskin.com\/#website\",\"url\":\"https:\/\/www.etemkeskin.com\/\",\"name\":\"blog website\",\"description\":\"Etem KESK\\u0130N\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.etemkeskin.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"tr\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/#webpage\",\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/\",\"name\":\"Currying at Javascript - blog website\",\"isPartOf\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#website\"},\"datePublished\":\"2022-05-13T12:18:29+00:00\",\"dateModified\":\"2022-05-13T12:25:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\"},\"description\":\"Currying is an important technique in functional programming. It is asked as an interview question in many interviews.Currying technique is the process of transforming a function so that it is called with a single parameter like f(a)(b)(c) each time, instead of calling it to take multiple parameters as in f(a, b, c).\",\"breadcrumb\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/#breadcrumb\"},\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2022\/05\/13\/currying-at-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ana sayfa\",\"item\":\"https:\/\/www.etemkeskin.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Currying at Javascript\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\",\"name\":\"etemkeskin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/#personlogo\",\"inLanguage\":\"tr\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"caption\":\"etemkeskin\"},\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/author\/etemkeskinyahoo-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/2589"}],"collection":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/comments?post=2589"}],"version-history":[{"count":16,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/2589\/revisions"}],"predecessor-version":[{"id":2609,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/2589\/revisions\/2609"}],"wp:attachment":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/media?parent=2589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/categories?post=2589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/tags?post=2589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}