Writing Arrow Functions with Parameters

you can pass parameters to arrow functions as well as shown in the following demo, these functions are only meant to be used once where normal functions can be re-used.

Demo

JS

function run_function() {
  "use strict";
  const double_me = (item) => item * 2;
  write_result(double_me(2));
  console.log(double_me(2));
  return double_me(2);
}

// write this function in one line example
/*
var myConcat = function(arr1, arr2) {
  "use strict";
  return arr1.concat(arr2);
};
*/

"use strict";
const myConcat = (arr1, arr2) => arr1.concat(arr2);
console.log(myConcat([1, 2], [3, 4, 5]));

// this is a common function just to write the content into the result div
function write_result(result) {
  var result_html = document.getElementById("result");
  result_html.innerHTML = result;
}

HTML

<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='run_function();' class='btn btn-primary mb-1'>Run Function</button>

Working Result

..

External Link for Writing Arrow Functions with Parameters

Other Items in javascript
Page Views

This page has been viewed 113 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹