Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!