docs: add output comment in Symbols article

This commit is contained in:
Radliński Ignacy 2022-06-27 22:44:33 +02:00 committed by GitHub
parent 30a5d5e2a7
commit f569591c07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -169,7 +169,7 @@ for (let key in user) alert(key); // name, age (no symbols)
*/!* */!*
// the direct access by the symbol works // the direct access by the symbol works
alert( "Direct: " + user[id] ); alert( "Direct: " + user[id] ); // Direct: 123
``` ```
[Object.keys(user)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property. [Object.keys(user)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.