How can I apply transformations on a 3D model?

I imported a 3D model, I want to rotate it using an animation loop. I tried storing the gltf scene in a variable but outside the scope of the loader it becomes null.

const model;
loader.load( './models/test.gltf', function ( gltf ) {
    model = gltf.scene;
    model.scale.set( 5,  5,  5);
}, undefined, function ( error ) {
    console.error( error );

function render(){
    model.rotation.y += 0.1;
    renderer.render(scene, camera);

This is what I want to do, but there’s an error saying that model is null

1st problem, const declarations must be initialized.
So change it to,

//const model;
let model;

2nd problem, in your render loop, you are using model before the model has finished loading and been initialised with gltf.scene.

So change it to,

///model.rotation.y += 0.1;
model && (model.rotation.y += 0.1)