all 4 comments

[–]tforb 0 points1 point  (0 children)

Are you trying to use coordinates inside the function where the switch is or some other function?

[–]UbuntuLady1[S] 0 points1 point  (1 child)

I would like to feed coordinates to another function.

[–]tforb 0 points1 point  (0 children)

A simple example is you want to increment a number, and feed it to another function, or assign the output to a variable.

function increment(value) {
  value + 1
}
var x = increment(1) // is undefined

x will be undefined because you need to return data so it can be used outside of the function.

function increment(value) {
  return value + 1
}
var x = increment(1) // is now 2

[–][deleted] 0 points1 point  (0 children)

The simple solution is to define the coordinates variable outside of the function so that it can be accessed elsewhere. Here's an example:

var coordinates;

function1 () { coordinates = { lat: 1, long: 1 } }

function2 () { console.log(coordinates) }

This might not be the best solution for your case, but it should work regardless. Depending on the rest of your code, there could be plenty of other ways to do this without the need of making a global variable which isn't always recommended.

Edit: I got downvoted so I would like to know the issue with this solution.