How can I optionally declare a variable using let
or const
? For example it would be possible to do:
if (variableNotMade) {
var makeVariable
}
But how can this be achieved using let
or const
instead of var
?
A similar post here shows that it's possible to do:
let makeVariable = variableNotMade ? foo : bar
Although this approach only really works if you have an else
.
Is there a suitable way to achieve this or should a different approach be taken?
Aucun commentaire:
Enregistrer un commentaire