My example
I have a string, that may be empty ("") or equal to "foo".
I want to create a variable my_string and assign to it the value "foo" of the string, or a value "empty" when the string is empty.
var my_string = string == "";
my_string = (string === "") ? "empty" : string;
Or
(string === "") && var my_string = string;
Are these good ways of doing what I am asking?
What are the recommended syntax for this case?
Aucun commentaire:
Enregistrer un commentaire