symbol(name)
The symbol()
function creates a unique and immutable data type that can be used as an identifier for object properties. This is a wrapper around JavaScript's native Symbol functionality.
Syntax
Parameters
none
: This function does not take any parameters.
Return Value
Returns a new Symbol object.
Symbols are particularly useful for:
Creating truly private or hidden properties
Adding non-enumerable properties to objects
Defining special behaviors for objects
Examples
Basic Symbol Creation
Using Symbols as Object Keys
Notes
Each symbol value is unique and immutable.
Symbols are not automatically converted to strings when used with string operations.
Symbols can be used to avoid property name collisions.
Unlike JavaScript, OSL's implementation may have some differences in edge cases.
Last updated
Was this helpful?