Question: Look at following codes about parameter destructuring. Indicate whats the output and why function getSentence({ subject, verb, object }) { return `${subject} ${verb} ${object}`; }

Look at following codes about parameter destructuring. Indicate whats the output and why

function getSentence({ subject, verb, object }) {

return `${subject} ${verb} ${object}`;

}

const o = {

subject: "I",

verb: "love",

object: "JavaScript",

};

getSentence(o);

------------------------------------

function getSentence({ subject, verb, object }) {

return `${subject} ${verb} ${object}`;

}

const o = {

subject: "I",

verb: "love",

object: "JavaScript",

};

getSentence(o);

----------------------------------------

function addPrefix(prefix, ...words) {

const prefixedWords = [];

for (leti=0; i

prefixedWords[i] = prefix + words[i];

}

return prefixedWords;

}

addPrefix("con", "verse", "vex");

----------------------------------------

2) Look at following codes about passing values into functions. Indicate whats the output and why

function f(x) {

console.log(`inside f: x=${x}`);

x = 5;

console.log(`inside f: x=${x} (after assignment)`);

}

let x = 3;

console.log(`before calling f: x=${x}`);

f(x);

console.log(`after calling f: x=${x}`);

----------------------------------------

function f(o) {

o.message = `set in f (previous value: '${o.message}')`;

}

let o = {

message: "initial value"

};

console.log(`before calling f: o.message="${o.message}"`);

f(o);

console.log(`after calling f: o.message="${o.message}"`);

----------------------------------------

function f(o) {

o.message = "set in f";

o = {

message: "new object!"

};

console.log(`inside f: o.message="${o.message}" (after assignment)`);

}

let o = {

message: 'initial value'

};

console.log(`before calling f: o.message="${o.message}"`);

f(o);

console.log(`after calling f: o.message="${o.message}"`);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!