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

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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