The Java Symbol.unscopables symbol represents an object value whose property names, inherited from its prototype, are omitted from the bindings within the environment.
NOTE:
- Setting a property to true in an unscopables object makes it unscopable and therefore it won't appear in lexical scope variables.
- Setting a property to false makes it scopable and thus it will appear in lexical scope variables.
Syntax
Example
[Symbol.unscopables]
Parameters
Object.
Return value
Examine the variables that are present within the boundaries of lexical scope.
Browser Support
| Chrome | 32 |
|---|---|
| Safari | 8 |
| Firefox | 29 |
| Opera | 19 |
Example 1
Example
//JavaScript to illustrate Symbol.toPrimitive
var obj = {
j: 1,
k: 2
};
obj[Symbol.unscopables] = {
//Setting a property to false will make it scopable
j: false,
//Setting a property to true in an unscopables object
k: true
};
with (obj) {
document.write(j);
}
//expected output: 1
Output:
Example 2
Example
<script>
//JavaScript to illustrate Symbol.toPrimitive
var obj = {
j: "Example",
k: "Core Java"
};
obj[Symbol.unscopables] = {
//Setting a property to false will make it scopable
j: false,
//Setting a property to true in an unscopables object
k: true
};
with (obj) {
document.write(j);
}
//expected output: Example
</script>
Output:
Output
Example