Skip to content

Using arrow functions

Vadim Dyachenko edited this page Jun 10, 2022 · 1 revision

2.3 function literals are cool, but what if you could have them shorter?

General idea

(pairs of what you can write instead of what)

var f = () => { print("hi!") };
var f = function() { print("hi!") }

var f = () => ;print("hi!"); // alt. - single-statement without curly brackets
var f = function() { print("hi!") }

var f = () => 1;
var f = function() { return 1; }

var f = (a, b) => a + b;
var f = function(a, b) { return a + b; }

Argument types and optional arguments are supported.