What does "!!" mean in Typescript?

Asked

Viewed 308 times

0

Example:

this.autenticator.logarExemplo(form.nome, form.senha,
usuario.idx, usuario.idy, !!usuario.login).subscribe(
  executar tarefas;
);
  • What would be the !! ?
  • This symbol belongs to Typescript exclusively?
  • Has any relation to the symbol || (or) ?

1 answer

1

The '!! ' is when you are denying a denial. Example

x = false;
console.log(!x) // true;
console.log(!!x) // false;

It is not exclusively typescript, it is the negation signal. Can be used together with OR condition (||) but there is no specific relationship between them.

Example of use of '!! ' and ||:

if(!!x == false || !!x) {
    console.log('x é falso');
}
  • Very cool! But what the need to use it then if I’m basically saying that x will be the same thing it already is. And another question: !! is used only for boleanos values?

  • 1

    Sometimes you need to check any structure as boolean, like a string in Javascript, since 'text of any size' is true and double or single quotes without anything is false. Not to pass the whole structure to the check you deny the first time to make the boolean value and consume less resources and deny the second not to modify the expected result.

Browser other questions tagged

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