What does it mean when the console returns the function itself?

Asked

Viewed 60 times

0

Edited. The console is returning the function itself as a response, not the function result.

The goal is for the function to say whether or not one value is greater than the other.

let primeiraVariavel = 34;
let segundaVariavel = 10;

function resultado() {
 return primeiraVariavel > segundaVariavel ? "verdadeiro" : "falso";
}
console.log(resultado);

2 answers

4


Because you are explicitly ordering the function to be displayed:

console.log(resultado);

And not her return. To display the return you need to make the function call:

console.log(resultado());
// ------------------^^

Thus will be displayed verdadeiro.

let primeiraVariavel = 34;
let segundaVariavel = 10;

function resultado() {
 return primeiraVariavel > segundaVariavel ? "verdadeiro" : "falso";
}

console.log(resultado());

2

console.log(result); replace with console.log(result());

When you don’t put the "()", you just reference and don’t call the function.

Browser other questions tagged

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