Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Input & Output Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following is used to print output in the browser console?

a)

print()

b)

document.write()

c)

console.log()

d)

alert()

2.

What does the alert() method do in JavaScript?

a)

Prints text in console

b)

Displays a popup message box

c)

Writes to HTML page

d)

Takes user input

3.

Which method is used to take input from the user through a popup box?

a)

console.log()

b)

document.write()

c)

prompt()

d)

alert()

4.

What does document.write("Hello"); do?

a)

Displays a message in the console

b)

Writes directly to the HTML page

c)

Shows a popup

d)

Logs an error

5.

What type of value does prompt() return?

a)

Number

b)

Boolean

c)

String

d)

Object

6.

Which of the following methods is used to get input from an HTML form?

a)

prompt()

b)

getElementById().value

c)

console.log()

d)

alert()

7.

Which statement correctly outputs text without adding a new line in Node.js?

a)

console.log("Hello");

b)

alert("Hello");

c)

process.stdout.write("Hello");

d)

document.write("Hello");

8.

Which of the following is NOT a valid browser output method?

a)

console.log()

b)

alert()

c)

document.write()

d)

process.stdout.write()

9.

The innerHTML property is used to:

a)

Modify the content of an HTML element

b)

Display popup alerts

c)

Clear console logs

d)

Get user input

10.

What will the following code output in the console? console.log("Hi" + 5 + 5);

a)

Hi10

b)

10Hi

c)

Hi55

d)

Error

11.

What is the default data type returned by prompt()?

a)

String

b)

Number

c)

Boolean

d)

Null

12.

To convert prompt input to a number, which method is used?

a)

parseInt()

b)

parseString()

c)

String()

d)

alert()

13.

In Node.js, which module is used for taking input from users?

a)

fs

b)

readline

c)

http

d)

express

14.

Which of the following statements is true about document.write()?

a)

It can overwrite the entire HTML document

b)

It runs only in Node.js

c)

It is used for console debugging

d)

It is the same as alert()

15.

What will happen if you run prompt() in Node.js?

a)

It shows an input box

b)

It throws an error

c)

It logs to console

d)

It returns null

16.

Which is the correct way to output “Hello World” inside an HTML paragraph with id demo?

a)

document.write("Hello World");

b)

demo.innerHTML = "Hello World";

c)

document.getElementById("demo").innerHTML = "Hello World";

d)

alert("Hello World");

17.

What is the purpose of console.error()?

a)

Prints output in red color as an error

b)

Displays an alert box

c)

Writes HTML code

d)

Clears console logs

18.

Which method is used to close the readline interface in Node.js?

a)

rl.stop()

b)

rl.end()

c)

rl.close()

d)

process.exit()

19.

Which of the following displays a message box with OK and Cancel buttons?

a)

prompt()

b)

alert()

c)

confirm()

d)

console.log()

20.

Which of the following will correctly print a variable’s value on the webpage? let name = "Deepan";

a)

alert(name);

b)

console.log(name);

c)

document.write(name);

d)

print(name);

21.

console.log("JavaScript" + " Rocks!"); What will be printed in the console?

a)

JavaScript + Rocks!

b)

JavaScript Rocks!

c)

undefined

d)

Error

22.

alert("Welcome " + "User!"); What happens when this code runs in a browser?

a)

Prints “Welcome User!” on the webpage

b)

Displays a popup box with “Welcome User!”

c)

Logs text to console

d)

Throws an error

23.

let name = prompt("Enter your name:"); console.log("Hi " + name); If user enters Deepan, what will appear in console?

a)

Hi name

b)

Hi "Deepan"

c)

Hi Deepan

d)

Nothing will appear

24.

document.write("Result: " + (5 + 3)); What will be displayed on the webpage?

a)

Result: 5 + 3

b)

Result: 8

c)

Result: 53

d)

Nothing, as document.write is deprecated

25.

let x = prompt("Enter a number:"); console.log(typeof x); If user enters 10, what is logged in console?

a)

number

b)

string

c)

object

d)

undefined

26.

let a = prompt("Enter first number:");

let b = prompt("Enter second number:");

console.log("Sum =", parseInt(a) + parseInt(b));

If user enters 5 and 7, output will be:

a)

Sum = 57

b)

Sum = 12

c)

Sum = 5 + 7

d)

Error

27.

What will be shown inside the paragraph?

a)

Nothing

b)

undefined

c)

Hello JS!

d)

Error

28.

process.stdout.write("Hello ");

process.stdout.write("World!");

What is printed in the terminal?

a)

Hello World!

b)

Hello World!

c)

Hello only

d)

undefined

29.

If the user clicks Cancel, what happens?

a)

Alert shows “File deleted”

b)

Alert shows “Cancelled”

c)

Nothing happens

d)

Error

30.

let name = "Alex";

let score = 90;

console.log(`Student ${name} scored ${score} marks.`);

What will be the console output?

a)

Student name scored score marks.

b)

Student Alex scored 90 marks.

c)

Student ${name} scored ${score} marks.

d)

undefined