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 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.