JavaScript Symbol for() Method Last Updated : 07 Aug, 2023 Comments Improve Suggest changes Like Article Like Report The Symbol.for() is an inbuilt method in JavaScript that is used to search for the given symbol in a runtime-wide symbol registry and if found then it returns the same symbol otherwise it creates a new symbol with the same name of the given symbol into the global symbol registry and returns them. Syntax: Symbol.for(key); Here "Symbol" is the symbol that is to be searched into the runtime-wide symbol registry. Parameters: This method accepts a parameter "key" which is the key to the symbol and is used for the description of the symbol. Return value: This method returns the given symbol is found in the runtime-wide symbol registry otherwise a new symbol is created with the same name as the given symbol and returned. Example 1: In this example, we will use Symbol for() Method. javascript // Some symbols are created const symbol1 = Symbol.for('Geeks'); const symbol2 = Symbol.for(123); const symbol3 = Symbol.for("gfg"); const symbol4 = Symbol.for('789'); // Getting the same symbols if found // in the global symbol registry // otherwise a new created and returned console.log(symbol1); console.log(symbol2); console.log(symbol3); console.log(symbol4); OutputSymbol(Geeks) Symbol(123) Symbol(gfg) Symbol(789)Example 2: In this example, we will use Symbol for() Method. javascript // Some symbols are created const symbol1 = Symbol.for('a', 'b', 'c'); const symbol2 = Symbol.for(1, 2, 3); const symbol3 = Symbol.for(1 + 2); const symbol4 = Symbol.for("Geeks" + "for" + "Geeks"); // Getting the same symbols if found // in the global symbol registry // otherwise a new created and returned console.log(symbol1); console.log(symbol2); console.log(symbol3); console.log(symbol4); OutputSymbol(a) Symbol(1) Symbol(3) Symbol(GeeksforGeeks)In the above code, the key should not be multiple otherwise it accepts the first element as the key and discard the remaining elements and if some arithmetic operator is used in place of the key then this method considers that key as the result of the operation. Supported Browsers: Google Chrome 40 and above Edge 12 and above Firefox 36 and above Opera 27 and above Safari 9 and above Reference: https://devdocs.io/javascript/global_objects/symbol/for Comment More infoAdvertise with us K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Symbol JavaScript-Methods Explore JavaScript Tutorial 8 min read JavaScript BasicsIntroduction to JavaScript 4 min read JavaScript Versions 2 min read How to Add JavaScript in HTML Document? 3 min read JavaScript Syntax 6 min read JavaScript Output 4 min read JavaScript Comments 2 min read JS Variables & DatatypesVariables and Datatypes in JavaScript 6 min read Global and Local variables in JavaScript 4 min read JavaScript Let 6 min read JavaScript const 5 min read JavaScript Var Statement 7 min read JS OperatorsJavaScript Operators 5 min read Operator precedence in JavaScript 2 min read JavaScript Arithmetic Operators 5 min read JavaScript Assignment Operators 5 min read JavaScript Comparison Operators 5 min read JavaScript Logical Operators 5 min read JavaScript Bitwise Operators 5 min read JavaScript Ternary Operator 4 min read JavaScript Comma Operator 2 min read JavaScript Unary Operators 4 min read JavaScript in and instanceof operators 3 min read JavaScript String Operators 3 min read JS StatementsJavaScript Statements 4 min read JavaScript if-else 3 min read JavaScript switch Statement 4 min read JavaScript Break Statement 2 min read JavaScript Continue Statement 1 min read JavaScript Return Statement 4 min read JS LoopsJavaScript Loops 3 min read JavaScript For Loop 4 min read JavaScript While Loop 3 min read JavaScript For In Loop 3 min read JavaScript for...of Loop 3 min read JavaScript do...while Loop 4 min read JS Perfomance & DebuggingJavaScript | Performance 4 min read Debugging in JavaScript 4 min read JavaScript Errors Throw and Try to Catch 2 min read JS ObjectObjects in Javascript 4 min read Object Oriented Programming in JavaScript 3 min read JavaScript Objects 6 min read Creating objects in JavaScript 5 min read JavaScript JSON Objects 3 min read JavaScript Object Reference 4 min read JS FunctionFunctions in JavaScript 4 min read How to write a function in JavaScript ? 4 min read JavaScript Function Call 2 min read Different ways of writing functions in JavaScript 3 min read Difference between Methods and Functions in JavaScript 3 min read Explain the Different Function States in JavaScript 3 min read JavaScript Function Complete Reference 3 min read JS ArrayJavaScript Arrays 7 min read JavaScript Array Methods 7 min read Best-Known JavaScript Array Methods 6 min read Important Array Methods of JavaScript 7 min read JavaScript Array Reference 4 min read Like