Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda