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

208
Visualizações
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
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