CS220 Midterm Spring23 - Answers
CS220 Midterm Spring23 - Answers
1. SPA (Single Page Application) means that the navigation within Instagram is performed without
refreshing the whole page. TRUE
2. In the map() method, the indices of empty slots are replaced with undefined in the returned array.
FALSE
3. The filter() method will skip empty slots. TRUE
4. An arrow function must have always a name. FALSE
5. There is no automatic tool to convert from HTML to JSX. FALSE
A. npm build
B. npm run dev
C. npm serve
D. npm start
1
D. A React component is a JavaScript function that returns the HTML code of the Web
application.
11. We aim to display on the console the characters entered by the user in the input field. Choose
the correct solution:
2
</div>
);
}
12. We aim to write the App component as an arrow function. Choose the correct solution:
<div>
A <Search />
<List />
</div>
};
const App = () => {
return (
<div>
<Search />
B
<List />
</div>
);
};
App = () =>
<div>
C
<Search />
<List />
</div>
const App = () =>
<div>
D
<Search />
<List />
</div>
A. Virtual DOM
B. Real DOM
C. A and B
D. None of the above
14. Choose the correct syntax of arrow function for the following function:
function Msg() {
return "Good Morning";
}
3
B. Msg = () => "Good Morning";
C. Both A and B.
D. None of the above.
A. ReactDOM
B. DOM
C. Virtual DOM
D. Shadow DOM
19. Let’s consider the following code, choose the right alternative:
A. [undefined]
[1,2, undefined]
B. Error
C. [1,2, undefined]
[1,2, undefined]
D. [undefined]
[1,2]
4
B. Return a single root element.
C. Use curly braces for JavaScript.
D. Convert all HTML attributes to camelCase naming convention.
21. Let’s consider the following code, choose the right alternative(s) for the Disp component:
const info = [
{
fname: "Jane",
address: "NYC",
age: 25 ,
objectID: 0,
},
{
fname: "John",
address: "WDC",
age: 55 ,
objectID: 1,
},
{
fname: "Jack",
address: "LA",
age: 35 ,
objectID: 2,
},
];
const Disp=()=> {
return (
<ul>
{info.map(function (item) {
return (
<li key={item.objectID}>
<span>{item.fname}</span>
A <span>{item.address}</span>
<span>{item.age}</span>
</li>
);
})}
</ul>
);
};
5
function Disp(){
return (
<ul>
{info.map( (item)=> {
return (
<li key={item}>
<span>{item.fname}</span>
B <span>{item.address}</span>
<span>{item.age}</span>
</li>
);
})}
</ul>
);
};
function Disp(){
return (
<ul>
{info.map((item) {
return (
<li key={item.objectID}>
<span>item.fname</span>
C <span>item.address</span>
<span>item.age</span>
</li>
);
})}
</ul>
);
};
const Disp =>{
return (
<ul>
{info.map((item) {
return (
<li key={item.objectID}>
<span>{item.fname}</span>
D <span>{item.address}</span>
<span>{item.age}</span>
</li>
);
})}
</ul>
);
};
6
22. What will be the output of this code?
A. Hello world 1
B. Hello world 2
C. Hello world 1 Hello world 2
D. Error
24. We aim to convert the following function to an arrow function. Choose the correct answer.
function isBigEnough(value) {
return value >= 10;
}
7
25. Let’s consider the following HTML code. What is the correct conversion to JSX?
<>
<div className="awesome" style="border: 1px solid red">
<label htmlFor="name">Enter your name: </label>
A <input type="text" id="name" />
</div>
<p>Enter your HTML here</p>
</>
<div className="awesome" style={{ border: "1px solid red" }}>
<label htmlFor="name">Enter your name: </label>
B <input type="text" id="name" />
<p>Enter your HTML here</p>
</div>
<>
<div className="awesome" style={{ border: "1px solid red" }}>
<label htmlFor="name">Enter your name: </label>
C <input type="text" id="name" />
</div>
<p>Enter your HTML here</p>
</>
<div>
<div className="awesome" style="border: 1px solid red">
<label htmlFor="name">Enter your name: </label>
D <input type="text" id="name" />
</div>
<p>Enter your HTML here</p>
</div>
A. React component has multiple component definitions and can have multiple component
instances.
B. React component has only one component definition and can have multiple component
instances.
C. React component has only one component definition and can have only one component
instance.
D. React component has multiple component definitions and can have multiple component
instances.
8
27. How React performs the updates when a component changes the state explicitly?
A. Runs the diffing algorithm (compare DOM trees) to reconcile the changes. (2) React updates
the Virtual DOM relative to the components. (3) Updates the real DOM.
B. React updates the Real DOM relative to the components. (2) Updates the real DOM. (3) Runs
the diffing algorithm (compare DOM trees) to reconcile the changes.
C. React updates the Virtual DOM relative to the components. (2) Runs the diffing algorithm
(compare DOM trees) to reconcile the changes. (3) Updates the real DOM.
D. React updates the real DOM relative to the components. (2) Runs the diffing algorithm
(compare DOM trees) to reconcile the changes. (3) Updates the virtual DOM.
A. “Key” prop is a way for React to identify a newly added item in a list.
B. It is one of the attributes in HTML.
C. “Key” prop is used to look pretty, and there is no benefit whatsoever.
D. None of these.
30. What type of event is captured by the handler function in the component function?
A. OnChange event
B. Synthetic event
C. Handler event
D. Rendering event