Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 6 / 68

Writing your own function

This lesson covers the basics of writing a function in Julia, with the aim of producing code you can reuse.

You define a function with function name(args) ... end. Gathering work you do repeatedly under a name means you can run it just by calling it.

In the sample code, a greet function takes a name argument and returns an assembled greeting. Julia functions automatically return the value of the last expression evaluated, so an explicit return is not needed.

A common early stumble is that mechanism of returning a value without return. If you are used to other languages, a function with no explicit return feels odd — but this is Julia's proper design.

In professional work, gathering shared logic into functions reduces duplication and means a change only has to be made in one place.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)