Make Object Properties Private

Help please!my code is crashed

weā€™d love to help, but we need a bit more information. Preferably including a link to your codepen or a copy/paste of your code.

1 Like

What object? What is the language you are using? Java: add ā€œprivateā€ in front of declaration of the field you want to make private. Example : private String privateString = ā€œthis is privateā€; . For javascript it will be a bit tricky. You might have to wrap it in something like a function. function stuffInsideIsPrivate(){var thisIsPrivate = ā€œprivateā€;};.

You can do like this to make it private;

let obj = function() {

let p = ā€˜I am private variableā€™;
return {
getPrivate: () => {
console.logĀ§;
}
};
}();

obj.getPrivate();