Single-Expression Functions vs. Functions on All Levels

Explore function types by comparing single-expression and many-level approaches, and understand function levels, parameters, arguments, return types, and varargs.

Single-expression functions

Many functions in real-life projects just have a single expressionAs a reminder, an expression is a part of our code that returns a value., so they start and immediately use the return keyword. The square function defined below is a great example. For such functions, instead of defining the body with curly braces, we can use the equality sign (=) and just specify the expression that calculates the result without specifying return. This is single-expression syntax, and functions that use it are called single-expression functions.

Get hands-on with 1400+ tech skills courses.