Can you identify the behaviour of following code snippet? | JavaScript Output Questions | Problem Solving | JavaScript Copy
@Devtools Tech
If asked to glance over the following code snippet and identify the behaviour of the duplicate
function then what do you think is happening in the following code snippet?
const original = {
id: 'xhdyt0123',
link: 'https://www.youtube.com/watch?v=_eaCs-pzaVg',
metadata: {
title: 'Build Your Own Redux',
description: 'In this video we are going to see how we an build our own Redux',
},
published: true
}
const duplicate = (original) => {
if (!original.published) {
throw new Error('Your post needs to published before duplication');
}
const copy = {
id: +new Date(),
link: original.link,
metadata: original.metadata,
published: original.published
};
copy.metadata.title = `Copy of ${original.metadata.title}`;
return copy;
};
duplicate(original);
Option 1
The function duplicates a video post. It throws an error if the original video post isn’t published. It prepends “Copy of” to the new video post's title.
Option 2
The function duplicates a video post. It throws an error if the original video post is published. It prepends “Copy of” to the new video post's title.
Option 3
The function duplicates a video post and returns the copy.
Option 4
The function duplicates a video post. It throws an error if the original video post isn’t published. It prepends “Copy of” to the new video post's title and original video post's title.