TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Symbol unscopables Property

JavaScript Symbol unscopables Property with examples on javascript symbol methods, javascript symbol property, javascript tutorial, hasInstance, isConcatSpreadable, match, prototype, search, for(), keyFor(), toString(), unscopables, toPrimitive, split etc.

<< Back to JAVASCRIPT

JavaScript Symbol.unscopables Properties

The Java Symbol.unscopables symbol is an object value whose inherited property names are excluded from with environment bindings.

NOTE:

  1. Setting a property to true in an unscopables object makes it unscopable and therefore it won't appear in lexical scope variables.
  2. Setting a property to false makes it scopable and thus it will appear in lexical scope variables.

Syntax

[Symbol.unscopables]

Parameters

Object.

Return value

Check the variable appear in lexical scope variable.

Browser Support

Chrome 32
Safari 8
Firefox 29
Opera 19

Example 1

//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
Test it Now

Output:

1

Example 2

<script>
//JavaScript to illustrate Symbol.toPrimitive
var obj = { 
  j: "JavaTpoint", 
  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: JavaTpoint
</script>
Test it Now

Output:

JavaTpoint

Next TopicJavaScript Symbol




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf