Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
How does the double exclamation (!!) work in javascript?

I'm going through the Discover Meteor demo, and am struggling to figure out how exactly 'return !! userId;' works in this section:

Posts.allow({
  insert: function(userId, doc) {
  // only allow posting if you are logged in
    return !! userId;
  }
});
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

! is the logical negation or "not" operator. !! is ! twice. It's a way of casting a "truthy" or "falsy" value to true or false, respectively. Given a boolean, ! will negate the value, i.e. !true yields false and vice versa. Given something other than a boolean, the value will first be converted to a boolean and then negated. For example, !undefined will first convert undefined to false and then negate it, yielding true. Applying a second ! operator (!!undefined) yields false, so in effect !!undefined converts undefined to false.

In JavaScript, the values false, null, undefined, 0, -0, NaN, and '' (empty string) are "falsy" values. All other values are "truthy."(1):7.1.2 Here's a truth table of ! and !! applied to various values:

 value     │  !value  │  !!value
━━━━━━━━━━━┿━━━━━━━━━━┿━━━━━━━━━━━
 false     │ ✔ true   │   false
 true      │   false  │ ✔ true
 null      │ ✔ true   │   false
 undefined │ ✔ true   │   false
 0         │ ✔ true   │   false
 -0        │ ✔ true   │   false
 1         │   false  │ ✔ true
 -5        │   false  │ ✔ true
 NaN       │ ✔ true   │   false
 ''        │ ✔ true   │   false
 'hello'   │   false  │ ✔ true
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda