WorksheetsWPR final
Total questions: 125
Worksheet time: 1hrs 4mins
Which of these correctly describe the output of the JS code below? const list = [0, 1, '0', 'a', false]; let count = 0; for (const item of list) { if (item==0) { count++; } } console.log(count);
2
1
Error
3
Which of these correctly describe the output of the ExpressJS code below? async function demoData() { const response = await db.collection('words').updateOne({word: 'dog'}, { $set: {definition: 'friend'} }); }
Insert a new entry for the word 'dog' if it doesn't exist
Update the entry for the word 'dog' with new definition if it already exists or else insert a new entry
Update the entry for the word 'dog' with new definition if it already exists
Insert a new entry for the word 'dog' even when it already exists
Which of these correctly describe the output of the CSS code below? @media (max-width: 768px) { .menu a:hover { padding-left: 15px; } }
On devices with screen width greater than 768px, all the visited links move to the left 15px
On devices with screen width greater than 768px, the menu link moves to the right 15px when you mouse over it
On devices with screen width less than or equals 768px, the menu link moves to the right 15px when you mouse over it
On devices with screen width less than or equals 768px, all the visited links move to the left 15px
Which of these correctly describes the output of the ExpressJS code below? async function deleteDemoData() { const query = {}; const response = await db.collection('words').deleteOne(query); }
Error
Delete the first entry in the collection 'words'
Delete all the entries in the collection 'words'
No entry is deleted from the collection 'words'
Which of these correctly describes the output of the JavaScript code below? // modifies count = no. even numbers in range [min, max] function countEvens(min, max) { count = 0; for (const i = min; i <= max; i++) { if (i % 2 == 0) { count++; } } } let count; countEvens(5, 10); console.log(count);
3
undefined
0
Error
What do we call a data record in MongoDB?
Table
Row
Collection
Document
React is a
None of these
JavaScript framework
JavaScript library
In ReactJS, props can be used to pass
None of these
Event handler to component
Both of these
Properties to the component
Which of the following commands can be used in mongo shell to show all the databases in your MongoDB instance?
show databases
show dbs
ls dbs
show dbs-all
In NodeJS modules, the variables & functions can be exposed (to be accessed outside the module) using *
All of them
expose default
require
module.exports
Which of these lines of code FAILs to work in NodeJS?
const name = 'V8';
const button = document.querySelector('button');
console.log("V8");
None of these
Complete the code below to serve static files (html, css, js, img) from the same server (http://localhost:3000) server.js const express = require('express'); const app = express(); // TODO: serve static files app.listen(3000, function() { console.log("Listening on port 3000!"); });
app.use(express.static('public'))
app.use(express.static('static'))
require('express').static('/public')
app.static('public')
In JavaScript, a condition (productCost > 5) is used in an if statement. Which of the following values of productCost will result in this condition being evaluated as true?
5
5.1
4
0
Which of these is correct about the JS code below? const response = { status: 201, student: {id: 1001040015, name: 'Cong Nguyen', courses: ['SE1', 'DBS', 'WPR', 'MPR']} }; const json = JSON.stringify(response); console.log(json);
{'status':'201', 'student':{'id':'1001040015', 'name': 'CongNguyen', 'courses' : ['SE1', 'DBS', 'WPR', 'MPR']}}
{'status':201, 'student': {'id':'1001040015', 'name': 'Cong Nguyen', 'courses': ['SE1', 'DBS', 'WPR', 'MPR']}}
["status":"201", "student": {"id": "1001040015","name":"Cong Nguyen", "courses": {"SE1", "DBS", "WPR", "MPR"}}]
["status":"201", "student": ["id":"1001040015", "name":" Cong Nguyen", "courses": {"SE1", "DBS", "WPR", "MPR"}]]
Part of exception captured when we try to run the code below; what may cause this problem? const DATABASE_NAME = 'diary-db'; const MONGO_URL = mongodb://localhost:27017/$ {DATABASE_NAME}; let db = null; app.listen(8080, async function () { const mongoClient = await mongodb. MongoClient.connect(MONGO_URL); db= mongoClient.db(); }); Error: (node:572) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017] at Pool. (c:\nodes\server.js:431:11) at Pool.emit (events.js:189:13) at createConnection [...omitted...]
None of these
The database named 'diary-db' does not exist
The MongoDB database management process is not running on port 27017
Port 8080 is being used by another application (process)
Which of these is correctly implemented to toggle (show/hide) the content div? // css // html .hidden { Show/Hide display: none; This is demo content. } // js class Toggler { constructor(button, content) { this.content content; this._onClick= this._onClick.bind(this); button.addEventListener('click', this._onClick); } _onClick() { // CODE HERE.. } } const button = document.querySelector('button'); const content = document.querySelector('div'); new Toggler (button, content);
this.content.css.toggle('.hidden')
this.content.classList.toggle('hidden')
this.content.classList.add('hidden')
this.content.style.add('.hidden')
What is the correct HTML for creating an internal link (linked within the same webpage) to the bookmark named html?
A. <link href = "html"> Lesson 1.HTML </a>
B. <a id = "html"> Lesson 1.HTML </a>
C. <a href = "#html"> Lesson 1.HTML </a>
D. <a name = "html"> Lesson 1.HTML </a>
Which of these is correctly implemented in ExpressJS to serve the fetch from client as below? fetch('/search?key=' + encodeURI('FIT Hanu'));
app.get('/search', function(req, res) { const key= req.query.key; })
app.post('/search', function(req, res) { const key req.query.key; })
app.post('/search', function(req, res) { const key= req.body.key; })
app.get('/search', function (req, res) { const key= req.params.key; })
Which of these is correctly implemented in ReactJS to import our defined class Mobile Menu from file named App.js?
import MobileMenu from './App.js';
import MobileMenu from 'App.js';
from 'App.js' import MobileMenu;
from './App.js' import MobileMenu;
Which of these correctly describe the output of the ReactJS code below? class Header extends React.Component { constructor(props) { super(props); this.state = { favoritecolor: "red" }; } componentDidMount() { setTimeout(() => { this.setState({ favoritecolor: "yellow" }) }, 1000) } render() { return My Favorite Color is {this.state.favoritecolor} } } ReactDOM.render( , document.getElementById('root'));
Error
"My Favorite Color is red", but changed to "My Favorite Color is yellow" after 1 second
"My Favorite Color is red", and nothing change
"My Favorite Color is yellow", and nothing change
Which of these is NOT a preferred way to communicate between the two classes App and Present in the design below?
Give Present a reference to App in its constructor. Present can use this reference to call methods from App
Present dispatches custom events in response to actions. App listens for these events, then calls its corresponding methods
App can just call methods on Present since App has a list of the Present objects
App passes one or more of its methods to Present as parameters. Present calls them in response to corresponding actions.
Whenever the state is changed, React component will
be created again from scratch
re-renders the component
do nothing, you have to call render method to render the component again
None of these
In NodeJS, which of these below is used to execute the code of demo.js file?
None of these
nodejs demo.js
demo.js
node demo.js
In the React component life cycle, the static method getDerivedStateFromProps(props, state) is called when ____
None of these
Component is created for the first time
State of the component is updated
Both of these
Which of these correctly describe the output of the CSS code below? div { padding: 5px 10px; }
Space between the border and the content of the div is respectively, top & bottom: 5px, left & right: 10px
Space between the border of the div and the other elements is respectively, top & left: 5px, bottom & right: 10px
Space between the border of the div and the other elements is respectively, top & right: 5px, bottom & left: 10px
Space between the border and the content of the div is respectively, top & right: 5px, bottom & left: 10px
How many errors need to be corrected in the code below to make it run normally? class Alert { constructor (button) { this.button button; this.button.addEventListener('click', this._onClick); } } function _onClick() { alert("clicked!"); } } new Alert();
2
No errors
3
1
What is the correct JavaScript syntax to change the content of the HTML element below? This is a demonstration.
document.querySelectorAll("demo").innerHtml = "Hello World!";
document.querySelectorAll("#demo").innerHtml = "Hello World!"
document.querySelector('p.demo').innerHTML = "Hello World!"
document.querySelector("p#demo").innerHTML = "Hello World!"
Which of these HTML element below is MOST used to define important text?
A. <important>
B. <i
C. <b
D. <strong>
Which of these is correct to define an array in JavaScript?
let list = [1,2,3]
const list = (1,2,3);
const list-list.add(1); list.add(2); list.add(3);
int list = new int([1,2,3]);
Which of these correctly describe the output of the code below? Note: image kitty-cat.jpg has width= height=200px; // css // html img { <img src ="images/kitty-cat.jpg/> display: block; <img src ="images/kitty-cat.jpg/> width: 50px; <img src ="images/kitty-cat.jpg/> } <img src ="images/kitty-cat.jpg/> <img src ="images/kitty-cat.jpg/>
5 images display on 1 line, each image takes up 200px
5 images display on 5 lines, each image takes up 200px
5 images display on 5 lines, each image takes up 50px
5 images display on 1 line, each image takes up 50px
Which of these is INVALID built-in event in JavaScript?
mousepress
keyup
keydown
click
Which of these is correctly implemented in ExpressJS to serve the fetch from client as below? fetch('/search?key=' + encodeURI("FIT Hanu"));
app.get('/search', function(req, res) { const key req.query.key; });
app.post('/search', function(req, res) { const key req.query.key; });
app.post('/search', function(req, res) { const key req.params.key; });
app.get('/search', function(req, res) { const key req.params.key; });
Which of these is correctly implemented in JS to consume the API defined in ExpressJS server as below? app.post('/hello', function (req, res) { const name = req.body.name; res.json({ message: 'Hello ' + name + '!' }); });
async function hello() { const name = 'Cong Nguyen'; const response = await fetch('/hello?name=' + encodeURI(name),{ method: 'POST', }); const json = await response.json(); console.log(json.message); }
async function hello() { const name="Cong Nguyen"; const response = await fetch('/hello/$(name)'); const message = await response.text(); console.log(message); }
async function hello() { const name 'Cong Nguyen'; const response await fetch('/"hello"', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({name: name}) }); const json = await response.json(); console.log(json.message); }
async function hello() { const name "Cong Nguyen"; const response = await fetch('/"hello"', { method: 'POST', headers: { 'Content-Type': 'text/plain' }, body: (name: name) }); const message = await response.text(); console.log(message); }
Which of these correctly describe the output of the ExpressJS code below? async function browseDemoData() { const query = {}; const response = await db.collection('words').find(query); }
Return all the entries in the collection 'words'
No entry is returned from the collection 'words'
Return the first entry in the collection 'words'
Error
Which of these is correctly implemented in ExpressJS to serve static files (in a folder named public) from the same server?
app.use(express.static('public'));
app.use(app.static('public'));
express.serveStatic('public');
app.serveStatic('public');
Which of these lines of code is correct to import the Handlebars template engine library for use in ExpressJS?
const handlebars = require('express-handlebars');
const handlebars = require('handlebars');
const handlebars = import('express-handlebars');
const handlebars = import('handlebars');
Which of these correctly define a function component in React?
<AlertButton on={false} />
A.
class AlertButton extends React.Component {
render() {
if (this.props.on)
return <button>ON</button>
return <button>OFF</button>}}
function AlertButton(props) {
if (this.props.on) {
return <button>ON</button>}
return <button>OFF</button>}
class AlertButton extends React.Component {
constructor(props) {
super(props);}
render() {
if (this.props.on)
return <button>ON</button>
return <button>OFF</button>}}
function AlertButton(props) {
if (props.on)
return <button>ON</button>
return <button>OFF</button>}
Which of these is correct about HTML inline-block elements?
Small amount of content, no height or width
Take up the full width of the page (flows top to bottom)
Large blocks of content, has height and width
Small amount of content, has height and width
Where in an HTML document is the preferred place to refer to an external CSS file?
At the end of the document
At the end of <body> section
At the beginning of <body> section
In the <head> section
In NodeJS modules, the variables and functions can be exposed (to be accessed outside the module) using
require
expose default
module.exports
export
Fill in the blank: const http = require('http'); const server = http, (a) ((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello, World!\n'); });
Which of the following browser objects or functions are not accessible in Node.js?
All of the above
window
document
addEventListener
What is a web service?
A program that only works on a specific operating system
A type of database service
A software functionality that can be invoked over the Internet using common protocols
A software application that runs on a local machine
Which property is used to control the overflow of content that is too big to fit into an area?
overflow-style
overflow-control
overflow
overflow-size
What is the correct HTML tag for making a drop-down list?
A. <input type = "list'>
B. <input type="dropdown">
C. <list>
D. <select>
The file _____ contains metadata about the Node.js project, including dependencies and scripts.
index.js
app.js
package.json
server.js
Which of these is not a core feature of Express?
Templating
Routing
ORM
Middleware
How do you specify the space between words in a text?
word-spacing
letter-spacing
text-spacing
word-space
The policy that disallows fetching data from a different website is called?
BANS
VARS
IFPS
CORS
What is an HTML image map?
A map showing the locations of various images on a webpage
A map showing the geographical locations of images on a webpage
A technique to divide an image into clickable areas with different links
A graphical representation of an image in HTML
What will next() function do in Express middleware?
It will pass control to the next middleware function.
It will restart the request-response cycle.
It will throw an error.
It will end the response cycle.
What is the correct HTML for inserting an image?
A. <img href="image.gif" alt="My Image">
B. <img alt="image.gif">image.gif>
C. <image src="image.gif" alt="My Image">
D. <img src="image.gif" alt="My Image">
What does the POST verb in an HTTP request signify?
A resource is being updated
A resource is being fetched
A new resource is being created
A resource is being deleted
How do you make an element's text not wrap and stay on one line?
text-wrap: nowrap;
white-space: nowrap;
text-overflow: nowrap;
white-space: no-wrap;
<button id="demo">Click me!</button>
<script>
document.getElementById("demo")._____("____", myFunction);
</script>
(a)
Which property is used to control the display of the border's individual sides?
border-style
border
border-side-style
border-sides
Which of the following HTTP Status codes means "Internal Server Error"?
406
500
401
402
Why was asynchronous processing introduced in Node.js?
To reduce memory usage during application runtime
To simulate multi-threading and handle I/O tasks efficiently in a single-threaded environment
To enable Node.js to support multi-threading
To allow Node.js to run multiple programming languages
The file ______ contains metadata about the Node.js project, including dependencies and scripts.
package.json
node_modules
server.js
package-lock.json
Cookies are simple, small files/data sent to the server with a client request and stored on the server-side. Choose one.
True
False
Finish the following code to send a POST request using fetch. Do not add any unnecessary spaces. let params = new FormData(id("input-form")); fetch(url, { _____ : "POST", _____ : params })
(a)
What is the correct way to check if a variable x is of type "string" in JavaScript?
if (x === "string")
if (typeOf x === "string")
if (typeof x === "string")
if (x.type === "string")
What will be the output of the following code snippet? var arr = [1, 2, 3, 4, 5]; var slicedArr = arr.slice(1, 4); console.log(slicedArr);
[1, 2, 3]
[2, 3, 4]
[2, 3, 4, 5]
[1, 2, 3, 4]
What will be the output of the following code snippet? function delayLog() { for (var i = 1; i <= 5; i++) { setTimeout(function () { console.log(i); }, 1000); } } delayLog();
1, 2, 3, 4, 5
5, 5, 5, 5, 5
6, 6, 6, 6, 6
1, 6, 6, 6, 6
What will be the output of the following code snippet?
function foo() {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve("Promise resolved.");
}, 1000);
});
}
console.log("Start");
foo().then(function (result) {
console.log(result);
});
console.log("End");
A. Start, Promise resolved., End
B. Start, End, Promise resolved.
C. Promise resolved., Start, End
What will be the output of the following code snippet? async function foo() { return "Async function."; } console.log("Start"); foo().then(function (result) { console.log(result); }); console.log("End");
Start, Async function., End
Start, End, Async function.
Async function., Start, End
What will be the output of the following code snippet? Promise.resolve("First resolved.") .then(function (result) { console.log(result); return Promise.resolve("Second resolved."); }) .then(function (result) { console.log(result); return Promise.resolve("Third resolved."); }) .then(function (result) { console.log(result); return Promise.reject(new Error("Fourth rejected.")); }) .catch(function (error) { console.log(error.message); });
First resolved., Second resolved., Third resolved., Fourth rejected.
First resolved., Second resolved., Third resolved., Error: Fourth rejected.
First resolved., Second resolved., Third resolved., Promise {: Error: Fourth rejected.}
First resolved., Second resolved., Third resolved., Promise {: "Fourth rejected."}
Consider the following code snippet:
async function asyncFunction() {
throw new Error("Error in async function.");
}
console.log("Start");
asyncFunction().catch(function (error) {
console.log(error.message);
});
console.log("End");
Start, Error in async function., End
Start, End, Error in async function.
Error in async function., Start, End
Which global object provides functionality to control the Node.js runtime process?
Global
Runtime
Process
NodeControl
Which method is used to create a new instance of a server in Node.js?
http.createServer()
http.createInstance()
http.newServer()
http.createServerInstance()
Which of the following is a core module for handling paths?
url
dir
path
location
What does the stream module in Node.js provide?
Tools for creating WebSockets
Utilities for handling HTTP operations
A way to handle streaming data
Functions for dealing with promises
Which of the following allows Node.js to be scalable?
Multithreading
Event-driven architecture
Larger memory allocation
High CPU usage
What is the main difference between exports and module.exports in Node.js?
They are the same.
exports is for functions, while module.exports is for objects.
exports is a reference to module.exports.
module.exports is the legacy way to export modules.
Which of the following is NOT a core module in Node.js?
fs
http
express
url
Which method in the fs module is used to read a file asynchronously?
fs.readFile()
fs.readSync()
fs.openFile()
fs.read()
In which object are all the environment variables stored in a Node.js application?
env
process.env
node.env
app.env
Which of the following is used to import modules in Node.js?
Import { module } from 'module-name'
#include 'module-name'
require('module-name')
using module-name
What is the purpose of the --save flag in the npm install command?
To globally install a package
To save a backup of the current project
To save the package version in the package-lock.json
To save the package in the package.json dependencies
How do you retrieve the value of a specific cookie sent in a request in Express.js?
req.cookie.value
req.cookies[cookieName]
req.get('cookieName')
req.values.cookieName
What is the purpose of the ORDER BY clause in SQL?
It filters the rows returned by the SELECT statement.
It specifies the columns to be retrieved.
It creates a new table.
It orders the results in ascending or descending order.
What is the purpose of the GROUP BY clause in SQL?
It filters the rows returned by the SELECT statement.
It groups rows with the same values into summary rows.
It orders the results in ascending or descending order.
It specifies the columns to be retrieved.
What is the purpose of the HAVING clause in SQL?
It orders the results in ascending or descending order.
It filters the rows returned by the SELECT statement.
It specifies the columns to be retrieved.
It filters the summary rows created by the GROUP BY clause.
Which of the following best describes MongoDB?
Relational database
Spreadsheet program
Document-based NoSQL database
Graph database
In MongoDB, a record is equivalent to a:
Row
Table
Document
Database
Which of the following is the default port for MongoDB?
27017
8080
3306
5432
Which MongoDB command is used to display the database you are currently using?
show currentDatabase
show db
use db
db
To create or switch to a database in MongoDB, which command would you use?
createDatabase(name)
switchDatabase(name)
C. use <database_name>
D. db.<database_name>
Which of the following commands will show you all the collections in your current database?
show collections
list collections
display collections
db.collections()
How do you insert a new document into a collection in MongoDB?
A. db.<collection_name>.insert()
B. db.<collection_name>.newDocument()
C. db.<collection_name>.add()
D. db.<collection_name>.append()
Which of the following commands deletes a MongoDB database?
db.dropDatabase()
removeDatabase()
deleteDatabase()
destroyDatabase()
Which MongoDB method can be used to remove one or more documents from a collection?
A. db.<collection_name>.delete()
B. db.<collection_name>.remove()
C. db.<collection_name>.discard()
D. db.<collection_name>.drop()
What is the BSON in MongoDB?
A database engine
A query language
A backup tool
Binary representation of JSON
Which MongoDB command returns statistics about the database?
db.stats()
db.info()
db.data()
db.details()
What format does MongoDB use for its queries?
SQL
XML
BSON
XQuery
To update a document in a collection, which method is appropriate?
A. db.<collection_name>.modify()
B. db.<collection_name>.edit()
C. db.<collection_name>.revise()
D. db.<collection_name>.update()
Which of the following operations provides a sorted list of the documents in a collection?
A. db.<collection_name>.sort()
B. db.<collection_name>.arrange()
C. db.<collection_name>.listSorted()
D. db.<collection_name>.orderBy()
How can you backup your MongoDB database?
mongodump
mongobackup
mongosave
mongoarchive
Which tool can be used to import content from a BSON file into a MongoDB database?
mongoimport
mongorestore
mongoload
mongofetch
Which of the following commands lists all available MongoDB databases?
show dbs
list dbs
show databases
db.list()
Which MongoDB function is used to limit the number of results returned?
A. db.<collection_name>.count()
B. db.<collection_name>.skip()
C. db.<collection_name>.limit()
D. db.<collection_name>.restrict()
In which language is MongoDB written?
Python
Java
C++
Go
If you wish to retrieve only the specified fields of a document, which method would you use?
project()
show()
select()
find()
Which of the following ensures atomic transactions in MongoDB?
WriteConcern
Sharding
Indexing
Replication
Which of the following is NOT a valid logical operator in MongoDB?
$and
$or
$nor
$between
If you want to join collections in MongoDB, which operator would you use?
$join
$link
$lookup
$merge
What type of index in MongoDB allows you to search text fields?
Text index
Compound index
Unique index
Sparse index
Which MongoDB command provides execution statistics about query performance?
A. db.<collection_name>.stats()
B. db.<collection_name>.explain()
C. db.<collection_name>.details()
D. db.<collection_name>.analyze()
How do you create a unique index on a field in MongoDB?
{ uniqueKey: 1 }
{ index: "unique" }
{ type: "unique" }
{ unique: true }
What does the mongos command do?
Starts the MongoDB server.
Starts a shard server.
Starts the MongoDB routing service.
Dumps the MongoDB database.
Which MongoDB shell method is used to rename a collection?
A. db.<collection_name>.rename()
B. db.<collection_name>.renameCollection()
C. db.<collection_name>.changeName()
D. db.<collection_name>.alter()
Is JSON case-sensitive?
Yes
No
In JSON, keys must always be of which data type?
String
Number
Boolean
Object
What does the following JSON represent? { "firstName": "Ramesh", "lastName":"Fadatare", "age": 30, "isMarried": false }
An object with four properties
An array with four elements
A string with JSON data
A function with four arguments
JSON can be parsed using which of the following functions in JavaScript?
JSON.parse()
JSON.stringify()
JSON.decode()
JSON.encode()
What does the "null" value represent in JSON?
An empty string
Zero
An undefined value
No value or absence of value
What is the declarative way to render a dynamic list of components based on values in an array?
Using the reduce array method.
Using the component.
Using the Array.map() method.
With a for/while loop.
What will happen if you render an input element with disabled = {false}?
It will be rendered as disabled.
It will not be rendered at all.
It will be rendered as enabled.
You cannot set it false.
How can you set a default value for an uncontrolled form field?
By using the value property.
By using the defaultValue property.
By using the default property.
It is assigned automatically.
What is Callback?
The callback is a technique in which a method calls back the caller method.
The callback is an asynchronous equivalent for a function.
Both of the above.
None of the above.
The Node.js modules can be exposed using:
expose.
module.
exports.
All of the above.
Which of the following module is not a built-in node module?
zlib.
https.
dgram.
fsread.
Which of the following statement defines Express?
Express is an application framework that provides a robust set of features to develop desktop-based applications.
Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications.
Both of the above.
None of the above.
Which of the following is not a benefit of using modules in Express?
It provides a means of dividing up tasks.
It provides a means of reuse of program code.
It provides a means of reducing the size of the program.
It provides a means of testing individual parts of the program.
What is the default scope in the Node.js application?
Global.
Local.
Global Function.
Local to object.
