(Ad, please don’t block.)

Quizzes » Objects

1. Object literals

const obj = {
  true: 'a',
  ['true']: 'b',
  [true]: 'c',
};
const result = Object.keys(obj).length;

What happens?

2. Computed property keys (1/6)

const foo = 'bar';
const obj = {
  foo: 'a',
  [foo]: 'b',
};
const result = obj.foo;

What happens?

3. Computed property keys (2/6)

const foo = 'bar';
const obj = {
  foo: 'a',
  [foo]: 'b',
};
const result = obj.bar;

What happens?

4. Computed property keys (3/6)

const foo = 'bar';
const obj = {
  foo: 'a',
  [foo]: 'b',
};
const result = obj[foo];

What happens?

5. Computed property keys (4/6)

const foo = 'bar';
const obj = {
  foo: 'a',
  [foo]: 'b',
};
const result = obj[bar];

What happens?

6. Computed property keys (5/6)

const foo = 'bar';
const obj = {
  foo: 'a',
  [foo]: 'b',
};
const result = obj['foo'];

What happens?

7. Computed property keys (6/6)

const foo = 'bar';
const obj = {
  foo: 'a',
  [foo]: 'b',
};
const result = obj['bar'];

What happens?

8. Iterating over objects (1/4)

const symbol1 = Symbol('symbol1');
const symbol2 = Symbol('symbol2');

const obj = {
  name1: 0,
  [symbol1]: 0,
};
Object.defineProperties(obj, {
  name2: { enumerable: false, value: 0 },
  [symbol2]: { enumerable: false, value: 0 },
});

const result = Object.keys(obj);

What is the result?

9. Iterating over objects (2/4)

const symbol1 = Symbol('symbol1');
const symbol2 = Symbol('symbol2');

const obj = {
  name1: 0,
  [symbol1]: 0,
};
Object.defineProperties(obj, {
  name2: { enumerable: false, value: 0 },
  [symbol2]: { enumerable: false, value: 0 },
});

const result = Reflect.ownKeys(obj);

What is the result?

10. Iterating over objects (3/4)

const symbol1 = Symbol('symbol1');
const symbol2 = Symbol('symbol2');

const obj = {
  name1: 0,
  [symbol1]: 0,
};
Object.defineProperties(obj, {
  name2: { enumerable: false, value: 0 },
  [symbol2]: { enumerable: false, value: 0 },
});

const result = Object.getOwnPropertyNames(obj);

What is the result?

11. Iterating over objects (4/4)

const symbol1 = Symbol('symbol1');
const symbol2 = Symbol('symbol2');

const obj = {
  name1: 0,
  [symbol1]: 0,
};
Object.defineProperties(obj, {
  name2: { enumerable: false, value: 0 },
  [symbol2]: { enumerable: false, value: 0 },
});

const result = Object.getOwnPropertySymbols(obj);

What is the result?

12. Calling methods

const jane = {
  name: 'Jane',
  hello() {
    return `Hello ${this.name}!`;
  },
};
const func = jane.hello;

Which of these way of calling obj.hello work?

13. Prototype chains

const proto = { prop: 'a' };
const obj = Object.create(proto);

obj.prop = 'b';

What is proto.prop?

14. Prototype chains

const proto = {
  foo: 'p',
  logFoo() {
    console.log(this.foo);
  }
};
const obj = {
  foo: 'o',
  __proto__: proto,  
};

proto.logFoo.call(obj);
proto.logFoo.call(proto);

What happens?


Correct answers: 0 out of 0