Will JavaScript Function Without the ‘function’ Statement?

Share this article

Are you fed up typing ‘function’ in JavaScript code every few minutes? Should it be shortened? JavaScript inventor Brendan Eich thinks so and he revealed the following options during his keynote speech at Web Directions @media in London last month.

The first alternative is the florin symbol:

ƒ myfunction() { … }

I quite like it. It stands out nicely in code and it looks like the f in function. Unfortunately, you won’t find it in all coding fonts and it’s tricky to type (in Windows, hold down Alt and type 0131 on your numeric keypad. Mac users should try the Special Characters palette).

Next, we have the lambda symbol:

λ myfunction() { … }

The JavaScript geeks will think that’s very cool! Unfortunately, it suffers the same problems as the florin and you can’t even type it in Windows.

Finally, Brendan offered the plain old hash:

# myfunction() { … }

The majority of the audience voted for this symbol. It’s certainly easier to type, although I’m not sure it’ll stand out significantly in JavaScript code.

Other options may be raised and you should note that ‘function’ can still be used if you prefer it … your existing code won’t break.

As well as reducing your typing effort, the bandwidth savings could be colossal. For example, the minified jQuery library would become 4.3% smaller. That may only be 3Kb, but multiply that against the millions of downloads it receives every day.

Do you like any of these function-replacing options? Please cast your vote on the SitePoint poll or leave your comments below…

Craig BucklerCraig Buckler
View Author

Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form