Hello~
How did the return ‘know’ that “Math.random()>.2” is a boolean statement? Was it due to the statement being logic/boolean-base?
function isMonsterHit() {
return Math.random() > 0.2;
}
In the use of an expression, is return implied?
const x = () => Math.random() > 0.2;
console.log(x()) //truefalse
Why does logging const x return a lambda?
console.log(x); //λ
On the first question, yes, it is asking if the random number generated is more than 0.2.
On the second - yes an implicit return can be used on an arrow function where there is only 1 line of code in the execution statement.
The third one logged for me that this was a function: x.
1 Like
ILM
3
it is a boolean statement because when you use >
you have two possible results, true
or false
, the two boolean values
1 Like