I have tried to do it, but all I get is that output: ---> Symbol(Test) Is it even possible to get output like this(with single quotes in it): ---> Symbol('Test')
function getUnique(param) {
param = Symbol(param);
return param;
}
console.log(getUnique('Test')) // Symbol('Test') <--- I need to get that output
CodePudding user response:
I may be completely misunderstanding your question, but if you mean
Symbol('Test') <--- I need to get that output
You can append the single quote characters to the string like so:
const getUnique = (param) => {
const sym = Symbol(param);
return sym;
}
console.log(getUnique(`'test'`))
CodePudding user response:
[Updated] Not sure if this is what you want...
function getUnique(param) {
param = Symbol("'" param "'");
return param;
}
console.log(getUnique('Test'))
CodePudding user response:
The representation of what gets printed at the console is implementation dependent and could even vary from version to version of the same implementation. Running it in latest chrome gives an output of Symbol(Test) and firefox gives Symbol("Test"). It's the same thing either way: the console printed output is just a representation of the thing. It isn't actually any different, it's still a unique Symbol 'Test'.