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

120
Vistas
Javascript global variable undefined mobile safari Android works fine

Ok, so this has got me stumped, hoping one of you maybe can help me out. So, I have an app that is using capacitor to build. In my app I have global JS variables for example:

//globals 
var isCheckin = "";
var isUser = ""; 

etc...

On android, this works just fine (and previously, did work on IOS). But now, when I go to build it on IOS and run the application, my if statements for stuff like:

if(isCheckin !== "") {} 

No longer work, because isCheckin is coming back as undefined.

I was doing some searching and came across 'hoisting' and while I guess that may be the case why would:

  1. Android have no issue with the global?
  2. IOS used to work, but now comes back as undefined?

In-fact, the current version of the app, in app store still works just fine, but new builds are having this issue when global variables seem to get ignored by safari.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your definition of global variable should be defined.

Let's see this first example:

const myFunction = (() => {
  var foo = 'bar';
});

myFunction();
console.log(foo);

The variable is getting defined in the scope of a function. I.e. outside that scope it will be undefined.

What you can do, is removing var from it. See:

const myFunction = (() => {
  foo = 'bar';
});

myFunction();
console.log(foo);

Now the variable is global and can also be use outside the function. BUT if you set "use stricht", the variable will be undefined. See:

"use strict"
/* global console */


const myFunction = (() => {
  foo = 'bar';
});

myFunction();
console.log(foo);

So the cleanest way to get the value of the variable outside the scope is using let. See:

"use strict"
/* global console */

let foo;
const myFunction = (() => {
  foo = 'bar';
});

myFunction();
console.log(foo);

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