Why should we use an `immediately invoked function expression` (IIFE) vs. just creating an object?

I’m trying to understand why we should use an immediately invoked function expression ( IIFE ) over just creating an object in this scenario.

Example using IIFE:

                duck = { };
		let motionModule = (function () {
  			return {
    			glideMixin: function (obj) {
      				obj.glide = function() {
        				console.log("Gliding on the water");
      				};
    			},
    			flyMixin: function(obj) {
      				obj.fly = function() {
        				console.log("Flying, wooosh!");
      				};
    			}
  			}
  		}) ();

  		motionModule.glideMixin(duck);
  		duck.glide()

Versus just

		duck2 = { };
		let motionModule2 = {
			glideMixin: function (obj) {
      			obj.glide = function() {
        			console.log("Gliding on the water");
      			};
    		},
    		flyMixin: function(obj) {
      			obj.fly = function() {
        			console.log("Flying, wooosh!");
      			};
    		}
  			};

  		motionModule2.glideMixin(duck2);
  		duck2.glide()

Both of these execute console.log(“Gliding on the water”);

Hey,

From your code samples, there is no advantage in using an IIFE. An IIFE is used, among other things, to create a private scope.

For example if you wanted a counter that only your functions could modify:

let motionModule = (function () {
    let counter = 0;

    return {
        glideMixin: function (obj) {
      		obj.glide = function() {
      		    console.log(`Gliding on the water ${counter}`);

                    counter++;
      	        };
    	}
  };
}) ();

Thank you. This makes sense. Hadn’t learned about private scope yet. I understand the value of IIFE now.