What's the difference between the two code snippets below. I understand that the second one uses IIFE, however I am unable to understand what's the benefit of one over other. Can you please explain.
//First*******
var student=function student(name) {
this.name = name;
}
student.prototype.printMessage = function () {
console.log(this.name);
};
var st = new student("test");
st.printMessage();
//Second**
var student = (function () {
function student(name) {
this.name = name;
}
student.prototype.printMessage = function () {
console.log(this.name);
};
return student;
}());
var st = new student("test");
st.printMessage();