0
I know the exclamation (!
) is the denial of my expression, but in my function has two exclamations, example:
public get isChecarAlgo() {
return !!this.algumValorNumerico;
}
In that case, what does it mean? That the return will be true
or false
depending on whether or not it has value?
It is a dirty trick to convert a value or absence of this into boolean. The two exclamations serve to deny denial. So if it has value the result will be true and otherwise it will be false.
– Jéf Bueno
I figured... thank you so much for confirming!
– Develop For Web
This "truqe" is used when the value is Truthy or falsy to make a quick conversion. Similar to what some miniseries use to decrease where explicitly true and false is written, like
let x = true, y=false;
for that reasonlet x=!0, y=!1;
– Guilherme Nascimento
Just to let you know that this is a Javascript feature - as Typescript is a superset of the JS, ends up having this "by table".
– hkotsubo