Questions tagged [arrow-functions]

Questions about the compact function syntax in ECMAScript2015 (ES6) called "arrow functions" because of their use of "=>".

"Arrow functions" are a compact syntax for function definitions in ECMAScript 2015 (ES6).

Arrow functions differ from regular functions in several ways:

  • They cannot be named. They are anonymous only.
  • They are not constructors, don't have a .prototype and cannot be instantiated by new.
  • They use lexically scoped this instead of binding this dynamically on the call

Arrow functions are also available in CoffeeScript.

1520 questions
-2
votes
1 answer

Java script arrow function parameter error

I am having an issue where a variable outside of an arrow function is different than the parameter inside the arrow function. console.log("outside", group); return (
Rafael
  • 1
  • 1
-2
votes
1 answer

Turning an arrow function to a regular function javascript

i have to turn an arrow function to a regular one. The problem is that the arrow function is pretty different from those i'm used to work with hence harder to transform. I need your help please. Here is the arrow function followed by the regular…
-2
votes
2 answers

How to convert from react component to arrow function

I was trying to convert the React component below to arrow function. import { Jsme } from 'jsme' export default class App extends Component { logSmiles(smiles) { console.log(smiles) } render () { return (
harsh
  • 435
  • 2
  • 6
  • 13
-2
votes
1 answer

How to convert a function to arrow function inside an object

let object = { name : "Aditya", age : 20, printIt : function(){ console.log(this.name + " " + this.age) } } in above object i want to change printIt function in to an arrow function i tried as below but it is not…
kichu
  • 121
  • 1
  • 1
  • 11
-2
votes
1 answer

Arrow function output in Javascript

I was reading about arrow function in js. There I found one question. var arguments = [1, 2, 3]; var arr = () => arguments[2]; console.log(arr()); function foo(n) { var f = () => arguments[0] + n; return f(); } console.log(foo(3)); It's…
-2
votes
1 answer

JS : arrow function or array map?

Based on this code, I would like to use an arrow function, I am not really used to.. What's the best way to wrote it ? I would like to keep the same sort order. Since "selectedHeader" is like you can guess, a column variable based on a vue js…
Zabz
  • 59
  • 9
-2
votes
2 answers

Arrow function in javascript output?

I was learning about arrow function in js where I found one question console.log((function(x, f = () => x) { var x; var y = x; x = 2; return [x, y, f()]; })(1)); It's output is 2,1,1 but it should be 1,1,1. Can anyone explain it?
Deepak _8097
  • 27
  • 1
  • 4
-2
votes
5 answers

How can i define this peice of code inside arrow function, i want to use the iterating arrayElement?

I want the function to be able to output true or false, if the searchElement exists in the array it should return true or false. I know i could make use of a simple for loop and if-else combination but i want to make use of arrow function. I know by…
-2
votes
2 answers

How can I write alternative Code for Arrow functions?

I'm currently trying to do the React tutorial at https://en.reactjs.org/docs/state-and-lifecycle.html. In the code there is the following block with an arrow function. https://codepen.io/gaearon/pen/zKRqNB?editors=0010 componentDidMount() { …
-2
votes
1 answer

How to add multiple parameters in arrow function

already sorry for my stupid question but googling for it was not successful How can I add multiple parameters in an arrow functions. I want to add some properties "props" to the following function. const changeLocationHandler = async event => { …
Sam Simon
  • 5
  • 1
  • 3
-2
votes
4 answers

What is the difference between using () or {} after the arrow in an arrow function?

I usually always write an arrow function and when I need it to be multi-lined then I do "{}". However, I am watching a tutorial, and in it, he is writing this useEffect function: useEffect(() => { if (chatId) { db.collection("chats") …
-2
votes
2 answers

Why can't arrow function expression syntax be used in a JavaScript function declaration?

I'd like to declare a function like this: function calculateArea(length, width) {return length * width;} using arrow function expression syntax, like this: function calculateArea(length, width) => length * width; But doing so causes an error. 1)…
-2
votes
1 answer

Calculate sum of all vales of a particular property from a complex object using es6

Calculate sum of all vales of a particular property from a complex object using es6? calculate sum of all Salaries? let company = { sales: [ { name: 'Samin', salary: 1000 }, { name: 'Adib', salary: 1600 }, ], development: { …
-2
votes
1 answer

Arrow functions: What is this block explaining?

function readJson(sample) { d3.json("samples.json").then((data) => { var extract = data.metadata var emptyArray = extract.filter(object => object.id == sample); var finalArray = emptyArray[0]; var Visual =…
-2
votes
3 answers

JavaScript arrow function create li objects and add to HTML page

This front-end JavaScript code works, it creates li itens in a ol tag from a list of string data. I would like to do it in just one line... qelements.map(element => { let litag = document.createElement("li"); …
Daniel Carvalho
  • 125
  • 1
  • 3