Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!