TheDeveloperBlog.com

Home | Contact Us

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

JavaScript Symbol for() Method

JavaScript Symbol for() Method 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.for() Method

The JavaScript Symbol.for() method is used to search for existing symbol in a runtime-wide symbol registry with the provided key and returns if it found. Otherwise, a new symbol gets created with this key.

Syntax

Symbol.for(key);

Parameters

Key: The Keys to the symbol.

Return value

Existing symbol with the given key if found otherwise, a new symbol is created and returned.

Browser Support

Chrome 40
Safari 9
Firefox 36
Opera Yes

Example 1

<script>
//JavaScript to illustrate Symbol.for
// read from the registry
// if the symbol did not exist, it is created
var i = Symbol.for("i");
var o = Symbol.for("i");
 document.write(i==o); 
//expected output: true	
</script>
Test it Now

Output:

true

Example 2

<script>
//JavaScript to illustrate Symbol.key
// read from the registry
var JavaTpoint = Symbol.for('hello'); // If the Symbol does not exist, it's created
var Java = Symbol.for('hello'); // The Symbol exists, so it is returned
document.write(JavaTpoint === Java); // true
//expected output: true
</script>
Test it Now

Output:

true

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