AI solution for JavaScript Quiz on BFE.dev
57. non-writable
The code below outputs:
1
1
2
2
At the beginning, a
is defined as an empty object and then a new property "foo1" is added to it using Object.defineProperty()
method, with a value of 1
. Then, a new object b
is created using Object.create(a)
which means that b
will inherit from a
. A new property "foo2" is added to b
with a value of 1
.
The first console.log(b.foo1)
outputs 1, which is the value of the foo1
property that b
inherited from a
. The second console.log(b.foo2)
outputs 1, which is the value of the foo2
property of b
itself.
Then, foo1
and foo2
are both reassigned new values for b
. The third console.log(b.foo1)
outputs 2, which is now the value of foo1
on b
. Finally, the fourth console.log(b.foo2)
outputs 2, which is also now the value of foo2
on b
.