Alternative solution:
f(x::Number) = if (x < 1) 0 else 2 end
The if-elseif-else syntax in Julia will return the value of the expression to be executed, which imho makes the C-like ternary operator redundant. As in the case, all its functions are covered by a more readable alternative.
Looking at your previous attempts, I think it's worth mentioning that, unlike Python, you rarely need to explicitly use return (). Often you can simply return all returned if-elseif-else blocks, as with most lisp dialects. An explicit return is like goto or break, which you use to interrupt the control flow in exceptional cases.
source share