+1 vote
in JavaScript by
Which one of the following is the correct output for the given JavaScript code?

const object1 ={};  

a = Symbol('a');  

b =Symbol.for('b');  

object1[a]='harry';  

object1[b]='derry';  

constobjectSymbols=Object.getOwnPropertySymbols(object1);  

console.log(objectSymbols.length);  

a) 0

b) 1

c) 2

d) Error

1 Answer

0 votes
by

Answer: C

Reason: The method "Object.getOwnPropertySymbols()" used in the above program, returns a whole array of symbol properties, that are directly found on an object. In general, it returns an empty array, unless we have already set symbol properties on the object.

Related questions

+1 vote
asked Mar 22, 2021 in JavaScript by Robindeniel
+1 vote
asked Mar 22, 2021 in JavaScript by Robindeniel
...