Page MenuHomePhorge

symbols.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

symbols.js

import { test, summary } from './helpers.js';
console.log('Symbol Tests\n');
const sym1 = Symbol('test');
test('symbol typeof', typeof sym1, 'symbol');
const sym2 = Symbol('test');
test('symbols are unique', sym1 !== sym2, true);
test('symbol description', sym1.description, 'test');
const sym3 = Symbol();
test('symbol without description', sym3.description, undefined);
const obj = {};
const symKey = Symbol('key');
obj[symKey] = 'value';
test('symbol as key', obj[symKey], 'value');
const symFor1 = Symbol.for('shared');
const symFor2 = Symbol.for('shared');
test('Symbol.for same', symFor1 === symFor2, true);
test('Symbol.keyFor', Symbol.keyFor(symFor1), 'shared');
test('Symbol.keyFor local', Symbol.keyFor(sym1), undefined);
test('Symbol.iterator exists', typeof Symbol.iterator, 'symbol');
test('Symbol.toStringTag exists', typeof Symbol.toStringTag, 'symbol');
test('Symbol.hasInstance exists', typeof Symbol.hasInstance, 'symbol');
const custom = { [Symbol.toStringTag]: 'MyCustomType' };
test('Symbol.toStringTag custom', Object.prototype.toString.call(custom), '[object MyCustomType]');
summary();

File Metadata

Mime Type
application/javascript
Expires
Fri, Mar 27, 2:58 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512492
Default Alt Text
symbols.js (1 KB)

Event Timeline