Difference between If with and without keys

Asked

Viewed 80 times

0

I was following some courses of Nodejs, and I realized that in many of the cases is used a if more basic than traditional (I come from C#).

My question is the following: Is there any difference besides the syntax between them? Performance? Which one should I use?

Below is an example:

    if (typeof nome !== "undefined"){
        usuario.nome = nome;
    }
    if (typeof email !== "undefined"){
        usuario.email = email;
    }
    if (typeof password !== "undefined"){
        usuario.setSenha(password);
    }

    if (typeof nome !== "undefined") usuario.nome = nome;
    if (typeof email !== "undefined") usuario.email = email;
    if (typeof password !== "undefined") usuario.setSenha(password);

And in the case of:

link: process.env.NODE_ENV === "production" ? "https://DOMINIO.COM" : "http://localhost:8000"

  • @Luizfelipe Thanks! But in terms of performance, something changes?

  • I am almost sure that there is no gain or loss of performance, because I imagine that this is not even the main cause of any such problems. In most cases, this type of problem is linked to the implementation made by the programmer...

  • And as for its edition, it is also duplicate: How does this if/Else work with "?" and ":"?. Please search the site before opening a question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.