Erik Darling is always optimal:
Using the OPTIMIZE FOR UNKNOWN hint, or declaring variables inside of a code block to be used in a where clause have the same issue, though: they make SQL Server’s query optimizer make bad guesses, which often lead to bad execution plans.
You can read great detail about that here.
Read on for a bit of a deserved rant and an example to show why
OPTIMIZE FOR UNKNOWN often doesn’t solve the problem.