Why do we use the word 'value' in the function?

Asked

Viewed 62 times

-1

Because we use the word 'value' in the function?

this.x.subscribe(valor => {
        if(valor){
          alert(1);
        } else{
          alert(2);
        }
      });

It can be replaced by any other word?

  • 1

    This is a function, so value is a parameter and can have any name, but, pq not tested to see what happens if you change the name?

  • I believe his doubt is in the syntax of Arrow Function.

2 answers

3

The valor is the name of a variable that is a parameter of a Arrow Function. Note that the subscribe receives a callback function as a parameter, which traditionally would be written as:

function nome(qualquernome) { 
  // faz alguma coisa 
}

But the form that was used in your example is a summarized form. Therefore, since value is a parameter, it can have any name in Arrow Function:

this.x.subscribe(qualquernome => {
  if(qualquernome){
    alert(1);
  } else{
      alert(2);
  }
});

3

The value is an internal variable of the function, it could be any name, it expects to receive an element to work on it, in case the value, this variable can be used within the function to work its return.

Browser other questions tagged

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