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

214
Visualizações
How we have a return value of pop() function in JavaScript?

While I was recently studying JS coming from a C++ background, I found out that the pop() function of arrays has a return value in JS.

Now, in C++ we don't have a return value for pop_back() method because according to a paper by Cargill, it is impossible to design an exception-safe stack pop function as answered here

So how are things working in JS or am I missing something?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

None of the "Exceptions Thrown by T" cases pop up in JavaScript, because there simply is no assignment or construction operator invoked. JavaScript is a garbage-collected language, so everything is a handle to the actual object. Calling pop just shrinks the array by one and returns the handle that was there without doing anything more.

If you want to reason about it in terms of C++, everything is a std::shared_ptr<T>, so pop just move-constructs that to its return value, which is exception-free.

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