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

213
Views
When argument in method is allocated in javascript?

Can you let me know when method(function in a function)'s argument is allocated? if the arguments in method(in a function)is allocated when they are declared, there's no value of USERNAME.value when it is declared.

but If I put Stored Name as a argument of greeting in function store(which is call back function used for event),null comes out even if I put my user name on in input box. However, If I put USERNAME.value, it works properly.

This is my js code,

const USERNAME = document.getElementById("username");
const Form = document.querySelector("form");
const HIDDEN = "hidden";
const h2 = document.querySelector("h2");
const KEY = "username";

function greeting(who) {
    h2.innerText = `Hello, ${who}`;
    h2.classList.remove(HIDDEN);
}

function store(event) {
    event.preventDefault();
    localStorage.setItem(KEY, USERNAME.value);
    Form.classList.add(HIDDEN);
    greeting(StoredName);
}
const StoredName = localStorage.getItem(KEY);


if (StoredName == null) {
    Form.classList.remove(HIDDEN);
    Form.addEventListener("submit", store);

} else {
    greeting(StoredName);

}

and this is my html code.

<!DOCTYPE html>
<html lang="en">

<head>
    <link rel="stylesheet" href="practice.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2 class="hidden"></h2>
    <form action="" class="hidden">
        <input type="text" name="" id="username">
        <input type="submit" value="">
    </form>
    <script src="practice.js"></script>
</body>

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