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

151
Visualizações
Can someone explain where the "messages" key comes from?

I am following a tutorial and I understood everything up until everything beyond where I declared the let variable.

function submitMessage(event) {
    event.preventDefault();
    const email = document.getElementById("email").value;
    const fullName = document.getElementById("fullName").value;
    const feedbackType = document.getElementById("feedbackType").value;
    const comment = document.getElementById("comment").value;
  
    const messageObject = {
        email,
        fullName,
        feedbackType,
        comment
    };

    let currentMessages = [];

    if (window.sessionStorage.getItem("messages")) {
        currentMessages =
            JSON.parse(
                window.sessionStorage.getItem("messages")
            );
    }
  
    currentMessages.push(messageObject);
  
    window.sessionStorage.setItem(
        "messages",
        JSON.stringify(currentMessages)
    );
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You're setting the "messages" key for the session storage here:

window.sessionStorage.setItem(
    "messages", // arbitrary key name
    JSON.stringify(currentMessages) // value to store for this key
);
about 4 years ago · Juan Pablo Isaza Relatório

0

let currentMessage is an empty array that will hold messageObject variable expressed few row before.

After currentMessage there is a step that setup a session store that we going to call "messages".

The window.sessionStorage function is used to save some data inside the browser, in our case currentMessage. In this way if your refreshed the browser page you will able to get the last data save in window.sessionStorage.

So in the first step this function try to get messages object from the session storage that we have e called messages.

Then, one fetched it will push the currentMessage inside it with setItem, so after you reload the browser you will be able to retrieve the array passing through the session storage getItem and to get this value it need to search inside some key and the key is messages, in other word the key in the session storage that can hold our 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