JavaScript Interview Questions - Question 12 #javascript #coding #interview #js

preview_player
Показать описание
@ByteWarpDev Presents
JavaScript Interview Questions

Question - 12:
const obj = {
a: 1,
b: 2,
c: 3
};

obj[key] = obj[key] ? obj[key] * 2 : 4;
});

Options:
a) { a: 2, b: 4, c: 6 }
b) { a: 2, b: 4, c: 6, d: 4 }
c) { a: 2, b: 4, c: 6, d: 8 }
d) { a: 1, b: 2, c: 3, d: 4 }

Answer:
b) { a: 2, b: 4, c: 6, d: 4 }

Explanation:
2. Pushing 'd' results in ['a', 'b', 'c', 'd']
3. Iterating over these keys, existing values are doubled and d is set to 4
4. The final object is { a: 2, b: 4, c: 6, d: 4 }

#javascript #interview #questionsandanswers #coding #javascriptinterviewquestions
Рекомендации по теме
join shbcf.ru