Scope outside of font loader function

Hello I want to access text object outside of loader function

The code looks like this

var mainText;
const loader = new THREE.FontLoader();
loader.load( 'Inconsolata_Regular.json', function (font) {
  const color = 0xffffff;
  const matLite = new THREE.MeshBasicMaterial( {color: color,transparent: true,side: THREE.DoubleSide} );

  const message = "My Text";

  const shapes = font.generateShapes( message, 10 );
  const geometry = new THREE.ShapeGeometry(shapes);
  const xMid = - 0.5 * ( geometry.boundingBox.max.x - geometry.boundingBox.min.x );
  geometry.translate( xMid, 0, 0 );
  var mainText = new THREE.Mesh(geometry, matLite);
  shapes.push.apply( shapes, holeShapes );
} );

and i want to access mainText in moveCamera function bu that doesnt work. Nothing seems to exit this loader function i have tried defining text variable that i assigned some string in the function and then console.loggging that variable but that didnt work either and I have no idea why.

Write the line like so:

mainText = new THREE.Mesh(geometry, matLite);

Otherwise the mainText variable defined outside of the onLoad() callback will be undefined.