0

I am relatively new to programming and am having difficulty understanding what " () => " means when used as a parameter.

I couldn't find any solution online to explain what this meant and I was quite confused when I saw it because I learned that the second parameter of the addEventLister() method is meant for your function.

addEventListener('resize', () => {

canvas.width = innerWidth

canvas.height = innerHeight

})

So my assumption is its a short hand term to write a function, but correct if I'm wrong? I want to because I seen it in multiple lines of code now and would appreciate an explanation.

  • 1
    It's an arrow function declaration. [The article on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) explains it in detail. – rishat Feb 09 '19 at 00:06
  • It's an arrow function. It is not a shorthand. The syntax is shorter than a regular function expression, but the behaviour is different too. If it doesn't use `this`, like the one in your example it's pretty much the same as a regular function. – Paul Feb 09 '19 at 00:08

0 Answers0