# Optional Keyword arguments

**URL:** <https://discourse.julialang.org/t/optional-keyword-arguments/78353>\
**Category:** General Usage\
**Created:** [March 23, 2022, 8:25pm UTC](https://discourse.julialang.org/t/optional-keyword-arguments/78353 "2022-03-23T20:25:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [March 23, 2022, 9:40pm UTC](https://discourse.julialang.org/t/optional-keyword-arguments/78353/2 "2022-03-23T21:40:33Z")

</div>

Your first example definition uses a _optional positional_ argument and not a keyword argument. Your second example definition uses a keyword argument named `tl`. In Julia, when you call a function with a keyword argument you must use this name, as you discovered (`either g(x; tl=y)` or `g(x; tl)` which is just a shorthand for `g(x; tl=tl)`.

Now, to the question about defaults: A common way is to use `nothing` as a default, and check for that inside the function body, for example:

```julia
function g(ti::AbstractVector; tl = nothing) # or tl::Union{Timelimits,Nothing} = nothing
    if tl === nothing
        tl = Timelimits(ti[begin],ti[end])
    end
    # ...
end

```

---

_[View the full topic](https://discourse.julialang.org/t/optional-keyword-arguments/78353)._
