{"id":4314,"date":"2022-03-05T14:28:35","date_gmt":"2022-03-05T14:28:35","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4314"},"modified":"2022-03-05T14:28:36","modified_gmt":"2022-03-05T14:28:36","slug":"javascript-arrow-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/03\/05\/javascript-arrow-function\/","title":{"rendered":"Javascript Arrow function"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>The arrow function acts somewhat like the lamdba expression in Java. It allows you to define functions in a shorthand syntax. The sample code below shows how it can be used with and without parameters.<\/p>\n\n\n\n<p>The <em>this<\/em> keyword within an arrow function always points to the calling object, which is the window by default. If an arrow function is defined within a function then <em>this <\/em>points to the function.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n&lt;html&gt;\n\t&lt;head&gt;&lt;title&gt;Arrow Function&lt;\/title&gt;\n\t\n\t&lt;script&gt;\n\t\tfunction standard() {\n\t\t   return &quot;standard&quot;;\n\t\t}\n\n\t\tlet func = () =&gt; {return &quot;arrow&quot;;}\n\n\t\tdocument.write(standard() + &quot;&lt;br&gt;&quot;);\n\t\tdocument.write(func() + &quot;&lt;br&gt;&quot;);\n\n\t\tlet funcWithParams = (a,b) =&gt; {\n\t\t\tlet c = a+b;\n\t\t\treturn c;\n\t\t}\n\t\tdocument.write(funcWithParams(12,67) + &quot;&lt;br&gt;&quot;);\n\n\t\tlet funcThis = () =&gt; {\n\t\t\talert(this);\n\t\t}\n\n\n\t&lt;\/script&gt;\n\t&lt;\/head&gt;\n\n\t&lt;body&gt;\n\t    &lt;button onclick=&quot;funcThis();&quot; id=&quot;btn&quot; type=&quot;button&quot;&gt;Click Me&lt;\/button&gt;\n\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">standard\n arrow\n 79<\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW The arrow function acts somewhat like the lamdba expression in Java. It allows you to define functions in a shorthand syntax. The sample code <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/03\/05\/javascript-arrow-function\/\" title=\"Javascript Arrow function\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2463,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-4314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4314"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4314\/revisions"}],"predecessor-version":[{"id":4317,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4314\/revisions\/4317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/2463"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}