Salesforce JavaScript Developer Practice Exam 2025 – Comprehensive Test Prep

Question: 1 / 400

What is the output of the following console log for an object with duplicate keys?

{ a: "one", b: "two" }

{ b: "two", a: "three" }

{ a: "three", b: "two" }

When an object is defined in JavaScript with duplicate keys, the last occurrence of the key will override any previous values assigned to that key. This means that in cases where the same key appears multiple times, you only end up with the last assigned value.

In the scenario being considered, if we have an object like this:

```javascript

const example = {

a: "one",

b: "two",

a: "three"

};

```

The key `a` is present twice, with the first value being "one" and the second value being "three". Upon evaluation, JavaScript will ignore the first declaration of `a` and keep the last one, resulting in the object effectively being:

```javascript

{ a: "three", b: "two" }

```

Therefore, the output of the console log will indeed reflect that the key `a` has the value "three" while the key `b` retains the value "two". This aligns with the output described in the correct choice.

It is important to note that while you can define objects with duplicate keys, this practice can lead to confusion and bugs, so it is generally advisable to ensure all object keys are unique.

Get further explanation with Examzify DeepDiveBeta

SyntaxError

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy