Use the module pattern to create private variables and functions.
Source Code
let myModule = (function() {
let privateVar = 'private';
return {
publicMethod: function() {
console.log(privateVar);
}
};
})();
myModule.publicMethod(); // Access to private variable via public method