Home > Article > Backend Development > Why can't JS private variables be accessed?
<code>function Customer(name) { var risk = 0; this.name = name; } var customer = new Customer("aa"); console.log(customer.name); // aa console.log(customer.risk); // undefined </code>
Excuse me, why is customer.risk inaccessible but customer.name is accessible? Whose private variable is risk? Is it customer's? If so, why can't customer access his own private variable?