You can define a macro to deliver either \@gobble or \@firstofone depending on an \if..-switch.
You can define a macro to deliver either \@firstoftwo or \@scondoftwo depending on an \if..-switch.
The \@firstoftwo/\@scondoftwo-variant can be used for toggling between \phantom{\mbox{text}} and \@firstofone{\mbox{text}} or the like if you wish horizontal/vertical space to be reserved in case of text not being visible.
\documentclass{article}
\newif\ifhidestuff
\newcommand\StuffToHide{%
\csname @\ifhidestuff gobbl\else firstofon\fi e\endcsname
}%
\newcommand\StuffToShowOrHide{%
\csname @\ifhidestuff second\else first\fi oftwo\endcsname
}%
\newcommand\withoptarg[2][Optional Default]{%
This is the optional argument in parentheses: (#1)\
This is the mandatory argument in parentheses: (#2)
}%
\parindent=0pt \parskip=\medskipamount
\begin{document}
\verb|\hidestufffalse|:\hidestufffalse
\withoptarg{Mandatory}
\withoptarg[\StuffToHide{Optional User-Provided}]{Mandatory}
\StuffToShowOrHide{\withoptarg[Optional User-Provided]}{\withoptarg}{Mandatory}
\StuffToShowOrHide{\withoptarg[Optional User-Provided]}{\withoptarg[]}{Mandatory}
\withoptarg[\csname\StuffToShowOrHide{@firstofone}{phantom}\endcsname{\mbox{Optional User-Provided}}]{Mandatory}
\medskip\hrule
\verb|\hidestufftrue|:\hidestufftrue
\withoptarg{Mandatory}
\withoptarg[\StuffToHide{Optional User-Provided}]{Mandatory}
\StuffToShowOrHide{\withoptarg[Optional User-Provided]}{\withoptarg}{Mandatory}
\StuffToShowOrHide{\withoptarg[Optional User-Provided]}{\withoptarg[]}{Mandatory}
\withoptarg[\csname\StuffToShowOrHide{@firstofone}{phantom}\endcsname{\mbox{Optional User-Provided}}]{Mandatory}
\end{document}

If you wish to check for emptiness of an argument, i.e., the argument containing no token at all, I can offer two variants of the test.
One variant, \CheckWhetherNullVanilla is slow but doesn't require whatsoever TeX-extensions. It is based on using \string and applying brace-hacks while cranking out whether the closing } behind the empty argument was stringified or the first token, not being an opening {, of the non-empty argument was stringified or the first token, being an opening {, of the non-empty argument was stringified.
The other variant, \CheckWhetherNulleTeX is faster but requires eTeX-extensions as it is based on \detokenize, which in case of the ⟨general text⟩ provided via the macro-argument being empty delivers no token at all and otherwise delivers character-tokens whose category differs from the category of $ so that \ifcat can be used for doing the trick. (Instead of \ifcat$\detokenize{...}$...\else...\fi you could as well use \if\relax\detokenize{...}\relax...\else...\fi, but that relies on \relax not being redefined to deliver two subsequent equal tokens while I saw users doing all kinds of weird things within local scopes.)
Besides this, there also is a test for checking whether an argument is blank, i.e., is empty or contains explicit space-tokens only, \CheckWhetherBlank, which is based on \CheckWhetherNullVanilla or \CheckWhetherNulleTeX.
The tests look for the presence of tokens, but they don't expand expandable tokens, thus, e.g., \CheckWhetherNulleTeX{\empty}{empty}{not empty} yields not empty because, although just vanishing and not yielding any token when being expanded, \empty itself is a token and therefore \CheckWhetherNulleTeX's first argument is not empty but consists of the token \empty.
Remark:
In the subsequent coding-example you find \romannumeral.
This may seem confusing at first glimpse.
In the subsequent coding-example \romannumeral is not used for obtaining lowercase-roman-representation of whatsoever number but is (ab?)used for triggering a lot of expansion-work and flipping-macro-arguments-around-work so that in case of needing to be in control of expansion you don't need so many/long \expandafter-chains.
\romannumeral usually is used for "gobbling" tokens that form a TeX-⟨number⟩-quantity and in return for them delivering character-tokens which form the representation of the value of that TeX-⟨number⟩-quantity in lowercase roman numerals.
\romannumeral in any case triggers "gobbling" those tokens that form the TeX-⟨number⟩-quantity. But in case that TeX-⟨number⟩-quantity does have a value which is not positive, silently, i.e., without error-message or the like, no tokens at all are delivered in return.
Besides this while searching for tokens belonging to the TeX-⟨number⟩-quantity, expansion of expandable tokens is not suppressed.
Thus you can (ab?)use \romannumeral's searching for tokens belonging to the TeX-⟨number⟩-quantity for having (La)TeX doing a lot of expansion-work and flipping-macro-arguments-around-work as long as it is ensured that in the end a TeX-⟨number⟩-quantity is found whose value is not positive.
In the subsequent coding-example as "TeX-⟨number⟩-quantity whose value is not positive" the \chardef-token \UD@stopromannumeral is used.
This way the result of a macro is delivered after triggering two expansion-steps, e.g., after two "hits" with \expandafter:
The first one delivers the toplevel-expansion, whose first token is \romannumeral.
The second one triggers carrying out the \romannumeral-routine which in turn triggers all subsequent expansion-steps until the result is there.
In case you wish things to work out in tabular-environments/alignments etc as well, make sure that user-provided arguments, which might contain things like &, are nested in curly braces until the last expansion-step delivers the result. Otherwise the & of the user-provided-arguments might be taken for markers for the end of a table-cell at the wrong moment in time.
\documentclass[a4paper]{article}
\makeatletter
%%=============================================================================
%% PARAPHERNALIA:
%% \UD@firstoftwo, \UD@secondoftwo, \UD@stopromannumeral,
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`^^00}%
%% In the following code \romannumeral is not used for
%%-----------------------------------------------------------------------------
%% Check whether argument is empty, slow, but no eTeX-extensions or
%% the like required:
%%.............................................................................
%% \CheckWhetherNullVanilla{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\CheckWhetherNullVanilla[1]{%
\romannumeral\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\UD@stopromannumeral\UD@secondoftwo}{%
\expandafter\UD@stopromannumeral\UD@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty, based on \detokenize, thus eTeX-extensions
%% are required:
%%.............................................................................
%% \CheckWhetherNulleTeX{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
\newcommand\CheckWhetherNulleTeX[1]{%
\romannumeral\ifcat$\detokenize{#1}$%
\expandafter\expandafter\expandafter\UD@stopromannumeral
\expandafter\UD@firstoftwo\else
\expandafter\expandafter\expandafter\UD@stopromannumeral
\expandafter\UD@secondoftwo\fi
}%
%%-----------------------------------------------------------------------------
%% Check whether argument is blank (empty or only explicit space-tokens):
%%-----------------------------------------------------------------------------
%% -- Take advantage of the fact that TeX discards space tokens when
%% "fetching" _un_delimited arguments: --
%% \CheckWhetherBlank{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that
%% argument which is to be checked is blank>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not blank>}%
%% Instead of \CheckWhetherNulllVanilla you can as well use
%% \CheckWhetherNullleTeX
\newcommand\CheckWhetherBlank[1]{%
\romannumeral\expandafter\expandafter\expandafter\UD@secondoftwo
\expandafter\CheckWhetherNullVanilla\expandafter{\UD@firstoftwo#1{}{}}%
}%
\makeatother
\parindent=0pt \parskip=\medskipamount
\begin{document}
\verb|\CheckWhetherNullVanilla{}{empty}{not empty}|:\
\CheckWhetherNullVanilla{}{empty}{not empty}
\verb|\CheckWhetherNulleTeX{}{empty}{not empty}|:\
\CheckWhetherNulleTeX{}{empty}{not empty}
\verb|\CheckWhetherBlank{}{blank}{not blank}|:\
\CheckWhetherBlank{}{blank}{not blank}
\medskip\hrule
\verb|\CheckWhetherNullVanilla{ }{empty}{not empty}|:\
\CheckWhetherNullVanilla{ }{empty}{not empty}
\verb|\CheckWhetherNulleTeX{ }{empty}{not empty}|:\
\CheckWhetherNulleTeX{ }{empty}{not empty}
\verb|\CheckWhetherBlank{ }{blank}{not blank}|:\
\CheckWhetherBlank{ }{blank}{not blank}
\medskip\hrule
\verb|\CheckWhetherNullVanilla{{some}thing}{empty}{not empty}|:\
\CheckWhetherNullVanilla{{some}thing}{empty}{not empty}
\verb|\CheckWhetherNulleTeX{{some}thing}{empty}{not empty}|:\
\CheckWhetherNulleTeX{{some}thing}{empty}{not empty}
\verb|\CheckWhetherBlank{{some}thing}{blank}{not blank}|:\
\CheckWhetherBlank{{some}thing}{blank}{not blank}
\medskip\hrule
\verb|\CheckWhetherNullVanilla{something}{empty}{not empty}|:\
\CheckWhetherNullVanilla{something}{empty}{not empty}
\verb|\CheckWhetherNulleTeX{something}{empty}{not empty}|:\
\CheckWhetherNulleTeX{something}{empty}{not empty}
\verb|\CheckWhetherBlank{something}{blank}{not blank}|:\
\CheckWhetherBlank{something}{blank}{not blank}
\medskip\hrule
\verb|\CheckWhetherNullVanilla{\empty}{empty}{not empty}|:\
\CheckWhetherNullVanilla{\empty}{empty}{not empty}
\verb|\CheckWhetherNulleTeX{\empty}{empty}{not empty}|:\
\CheckWhetherNulleTeX{\empty}{empty}{not empty}
\verb|\CheckWhetherBlank{\empty}{blank}{not blank}|:\
\CheckWhetherBlank{\empty}{blank}{not blank}
\end{document}

\newcommand{\mymacro}[2][default]{definition}gets called by\mymacro[optional]{manditory}. You're specifically wanting to test if an argument is empty, but it's not optional. – Teepeemm Dec 22 '21 at 03:27optional-argumentstag? – Louis Deaett Dec 22 '21 at 03:49ifxand expansion works in TeX properly (in this particular case the\hiddencommand is already expandable, so you want to fully expand the argument before passing to the command) • learn expl3 • learn Lua and write the command in LuaTeX. I'd recommend the last approach – user202729 Dec 22 '21 at 03:49\foowhich printsfoobarand you want to it to printfoobarbarthen it would probably be very easy, but let's say if you want it to print justfoo, then it might require more efforts. All in all 1) without knowing the exact command which you want to amend, 2) without knowing the exact change you wish to see in the behavior; it would be tough to answer your question. – Niranjan Dec 22 '21 at 05:58\ifx#2does not test if#2is empty, it tests if the first two tokens in#2are the same so if#2isabcit is false and if it isoohit is true and typesetsh. – David Carlisle Dec 22 '21 at 08:22