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

165
Vistas
checking if a function with no return executed properly

I have simple function that aims to log a user in via localstorage, and then a second one that checks if the user can be found ( i need it separated because i need the logincheck elsewhere)

  logInUser(user: IPerson): Boolean {
    localStorage.setItem(this.userID, JSON.stringify(user));
    return this.isUserLoggedIn();
  }

 isUserLoggedIn(): Boolean {
    return Boolean(localStorage.getItem(this.userID));
  }

But this code seems bad to me because im not actually verifying that logInUser did its job, im just calling another function for this. I was thinking about converting this into a Promise of boolean and chain .then() but this doesnt work with setItem()

technically, setting something to a storage does not return anything, so i dont know how to verify correctly that it did and catch errors.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

If it returns without exception you can assume it worked. If you really want you can double check it with localStorage.getItem(this.userID) === JSON.stringify(user) and that's the ultimate test.

Exception might occur if you try for example to setItem in a snippet in stack overflow.

about 4 years ago · Santiago Gelvez Denunciar
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