TheDeveloperBlog.com

Home | Contact Us

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

JavaScript Symbol keyFor() Method

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

The JavaScript Symbol.keyFor() method uses the global symbol registry to look up the key for the symbol. So it doesn't work for non-global symbols. If the symbol is not global, it won't be able to find it and return undefined.

Syntax

Symbol.keyFor(Symbol);

Parameters

Symbol(required): The symbol to find a key.

Return value

A string representing the key for the given symbol if one is found on the global registry

Browser Support

Chrome 40
Safari 9
Firefox 36
Opera Yes

Example 1

<script>
//JavaScript to illustrate Symbol.keyFor
var i = Symbol.for("JavaTpoint");
var j = Symbol.for("Java");
document.write(Symbol.keyFor(i));
document.write("<br>");
document.write(Symbol.keyFor(j)); 
//expected output: JavaTpoint 
//Java
</script>
Test it Now

Output:

JavaTpoint
Java

Example 2

<script>
//JavaScript to illustrate Symbol.keyFor
var JavaTpoint = Symbol.for('Done');
var Java   = Symbol.for('Done');
document.write(JavaTpoint === Java);
document.write("<br>");
document.write(Symbol.keyFor(JavaTpoint));
//expected output: true
//Done
</script>
Test it Now

Output:

true
Done

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