Private function in Javascript

What is Private function ?

function that we can’t access directly.

–JS

function test () {
   var privatefunction = function () {
       alert('hello');
   }

   return {
       publicfunction : function () {
           privatefunction();
       }
   }
};

Now use it.

var a = test();

a.publicfunction();

This will be call privatefunction.

Leave a Reply

Your email address will not be published. Required fields are marked *