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

233
Visualizações
How to initialize to an empty array if my 'students' parameter is not passed

I am attempting to write code For the Bootcamp class (as shown in the code block) My goal is to write the code for the Bootcamp class so that if it the "students" parameter is not passed in, it is by default initialized to be an empty array from within the constructor parameter list itself. i took a stab at it with the function at the bottom of the code.

I am a bit confused regrading the proper syntax. Please See my Code Below

  • Thank you in advance :)
class Bootcamp{
    constructor(name,level,students){
        this.name = name;
        this.level = level;
        this.students = students;
    }
}
function student (students){
    return [];
} 
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could use a default value if the param is not passed. In this way, your properties will be initialized with default values.


    class Bootcamp{
        constructor(name = '', level = 0, students = []){
            this.name = name;
            this.level = level;
            this.students = students;
        }
    }

about 4 years ago · Juan Pablo Isaza Relatório

0

Say you have a list of students or an empty array using the below edited codes

class Bootcamp{
    constructor(name,level,students){
        this.name = name;
        this.level = level;
        this.students = students || []; //if students undefined, set it to empty 
        //array
    }
}
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