JavaScript Symbol.unscopables Properties - JavaScript Tutorial

JavaScript Symbol.unscopables Properties

BLUF: This tutorial on JavaScript Symbol.unscopables Properties provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Symbol.unscopables Properties

Understanding JavaScript Symbol.unscopables Properties is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience