function f(x, z = nothing)
y = 2x
tmp = z === nothing ? y^2 : z
return x + y + tmp
end
Because y only exists in the function body, it can’t be used in the default arguments. Default arguments can depend on other arguments though:
julia> f(a, b=2a) = b
f (generic function with 2 methods)
julia> f(1)
2