Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following JavaScript code?
const object1 = {};
a = Symbol(‘a’);
b = Symbol.for(‘b’);
object1[a] = ‘harry’;
object1[b] = ‘derry’;
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);

What will be the output of the following JavaScript code?
const object1 = {};
a = Symbol(‘a’);
b = Symbol.for(‘b’);
object1[a] = ‘harry’;
object1[b] = ‘derry’;
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);
a) 0
b) 2
c) 1
d) error

Answer: b
Explanation: The Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly on an object. This method returns an empty array unless you have set symbol properties on your object.

Join The Discussion