![]() |
VOOZH | about |
The symbol.valueOf() is an inbuilt method in JavaScript which is used to return the primitive value of a given symbol object. Syntax:
Symbol().valueOf();
Here Symbol() is the symbol object whose primitive value is to be found. Parameters: This method does not take any parameter. Return value: This method returns the primitive value of the given symbol object. JavaScript code to show the working of this method.
Example-1:
Output:
> Symbol(Geeks) > Symbol(Geeks) > Symbol(123) > Symbol()
Example-2:
Output:
> Symbol(GeeksforGeeks) > Symbol(5) > Symbol(2) > Symbol(1)
In the above code, it can be seen that the parameter of symbol object should be a single parameter otherwise it considers the first element as the parameter and remaining are discarded. If the parameter is an arithmetic operation then it considers them as the result of the operation as the parameter.
Supported Browser:
Reference: https://devdocs.io/javascript/global_objects/symbol/valueof