unable to modify global variable in javascript

unable to modify global variable in javascript


var address ="<%= params[:search] %>";
var lat;
var long;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
    lat = results[0].geometry.location.lat();
    long = results[0].geometry.location.lng();
//wanna use lat and long here!

browser always alert "undefined" when called outside the function, works when called from within the function.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

How To Add Stimulus to a Ruby on Rails Application

In this tutorial, you will install and use Stimulus to build on an existing Ruby on Rails Application that offers readers information about sharks.