es6 arrow functions and es5 functions comparison
es5 functions
var fs = require("fs"); function add(x, y) { return x + y; } var nums = [1,2,3,4,5]; var newNums = nums.map(function(n){return n*2}); console.log(add(3,10)); console.log(nums, newNums); fs.readFile("./arrow_functions.js", "utf-8", function (err, data) { if (err) console.log(err); console.log(data); });
Equivalent functions written in es6 with arrow notation. It’s basically replacing the keyword function with the arrow =>
let fs = require("fs"); let add = (x, y) => {return x + y;} let nums = [1,2,3,4,5]; let newNums = nums.map( (n) => {return n*2} ); console.log(add(3,10)); console.log(nums, newNums); fs.readFile("./arrow_functions.js", "utf-8", (err, data) => { if (err) console.log(err); console.log(data); });
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts