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

354
Visualizações
! function in javascript?

I apologize for my stupid question, I am not good at javascript and angularjs. I've been referencing the code of some projects, and I'm really confused about this, what it actually is !function(a,b,c){}(x,y,z). I have never seen it before. I am not good at javascript nor angularjs. Thanks for all the help!

!function (e, n, t) {
    "use strict";
    // code
}(window, angular, jQuery)
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It's a hacky way to immediately execute an anonymous function. If you were to define it normally (line starting with function, then it would immediately hoist the function as a function statement and force you to call it normally. Since the ! is in front of it, that lets the compiler evaluate it as a function expression, which can be invoked immediately. The exclamation mark here is the boolean not. Parenthesis or a plus sign would also work.

This would be equivalent code:

(e,n,t) => { /** */ }(window, angular, jQuery);

as would

(function (e,n,t) { /** */ })(window, angular, jQuery);

since the parenthesis will make the line be evaluated as an expression as well.

The anonymous function is being defined, and then called with the parameters window, angular, jQuery, which become e,n,t inside the function body.

Side note: I would not recommend writing functions like this, since it's uncommon syntax

about 4 years ago · Juan Pablo Isaza Relatório

0

it just simply tell the js to ignore this function and

it make it undefined Like This:

    function Demo(){
    console.log('log something');} 

OutPut Will Be :

log something

But If You Put A ! Before The Function The Result Would Be:

Demo is not defined

about 4 years ago · Juan Pablo Isaza 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