Arrow Functions in Twig

What are Arrow Functions in Twig?

Andrew gives an overview of arrow functions in Twig.

What is an arrow function?

  • An arrow func­tion is a short­hand way to write an anony­mous function
  • An anony­mous func­tion is a func­tion with­out a name or identifier
  • Arrow func­tions have implic­it return values

Here’s an exam­ple of an arrow func­tion (in gener­ic code):

	(value) => value * 5

This is what it would look like as a reg­u­lar function:

	function calc(value) {
		return value * 5
	}

As you can see, the arrow func­tion ver­sion is a more suc­cint way of writ­ing the same thing. Notice that there’s no explic­it return state­ment in the arrow func­tion, like there is in the sec­ond example.

Arrow Functions in Twig is made up of the following videos: