wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Numbers and Strings – MCQs

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the output of the following code?

let x = 10;

let y = "5";

console.log(x + y);

a)

15

b)

105

c)

10 + 5

d)

Error

2.

Which of the following methods converts a number to a string?

a)

toNumber()

b)

toText()

c)

toString()

d)

parseInt()

3.

What will be the output?

console.log(Number("123"));

a)

"123"

b)

123

c)

NaN

d)

undefined

4.

What is the output of:

console.log(parseInt("12.34"));

a)

12.34

b)

12

c)

13

d)

NaN

5.

Which method converts a number into an exponential notation?

a)

toExponential()

b)

toPrecision()

c)

toFixed()

d)

toLocaleString()

6.

What is the output of:

console.log(isNaN("Hello"));

a)

true

b)

false

c)

"Hello"

d)

NaN

7.

What is the output of:

console.log((0.1 + 0.2).toFixed(2));

a)

0.3

b)

"0.30"

c)

0.30

d)

"0.3"

8.

Which method returns NaN if the value cannot be converted into a number?

a)

parseInt()

b)

Number()

c)

toNumber()

d)

eval()

9.

What is the result of:

console.log(Math.floor(4.7));

a)

4.7

b)

4

c)

5

d)

NaN

10.

What does Math.random() return?

a)

A random integer

b)

A random decimal between 0 and 1

c)

A random number between 1 and 10

d)

Always 0

11.

What is the output of:

console.log("Hello".length);

a)

4

b)

5

c)

6

d)

Error

12.

Which method joins two strings?

a)

append()

b)

concat()

c)

combine()

d)

join()

13.

What will the following code display?

let str = "JavaScript";

console.log(str.toUpperCase());

a)

javascript

b)

JAVASCRIPT

c)

JavaScript

d)

Error

14.

What is the output of:

"Hello World".toLowerCase();

a)

"HELLO WORLD"

b)

"hello world"

c)

"hello World"

d)

"Hello world"

15.

Which of the following methods removes whitespace from both ends of a string?

a)

`trim()`

b)

`slice()`

c)

`replace()`

d)

`split()`

16.

What is the output?

let str = "JavaScript";

console.log(str.charAt(4));

a)

"S"

b)

"a"

c)

"s"

d)

"c"

17.

What will this return?

let text = "Hello, World!";

console.log(text.indexOf("World"));

a)

-1

b)

6

c)

7

d)

Error

18.

What is the result of:

"Hello".replace("H", "J");

a)

"Jello"

b)

"HJello"

c)

"HelloJ"

d)

Error

19.

What will be the output of:

"apple,banana,kiwi".split(",");

a)

`apple,banana,kiwi`

b)

`["apple", "banana", "kiwi"]`

c)

"apple banana kiwi"

d)

`["apple banana kiwi"]`

20.

What is the output?

let str = "JavaScript";

console.log(str.slice(4, 10));

a)

"Script"

b)

"JavaSc"

c)

"vaScri"

d)

"aScrip"

21.

What will be the output?

console.log(0.1 + 0.2 === 0.3);

a)

true

b)

false

c)

NaN

d)

undefined

22.

What is the output?

console.log(Math.max(10, 20, "30"));

a)

"30"

b)

30

c)

NaN

d)

undefined

23.

What does the following log?

console.log(parseInt("08"));

a)

8

b)

0

c)

NaN

d)

Error

24.

What is the output?

console.log(isFinite("200"));

a)

true

b)

false

c)

NaN

d)

undefined

25.

What does the following code output?

console.log(Math.round(4.5));

console.log(Math.floor(4.9));

console.log(Math.ceil(4.1));

a)

4, 4, 4

b)

5, 4, 5

c)

5, 5, 5

d)

4, 5, 4

26.

What is the output?

console.log("5" + 3 + 2);

a)

"532"

b)

"10"

c)

10

d)

"55"

27.

What is the result?

console.log("5" - 3 + 2);

a)

532

b)

4

c)

2

d)

NaN

28.

What will this print?

let text = "Hello World";

console.log(text.substring(6, 11));

console.log(text.slice(-5));

a)

"World", "World"

b)

"World", "Hello"

c)

"Hello", "World"

d)

"World", "rld"

29.

What is the output?

let str = "JavaScript";

str[0] = "Y";

console.log(str);

a)

"YavaScript"

b)

"JavaScript"

c)

Error

d)

undefined

30.

What is the result?

console.log("abc" == new String("abc"));

console.log("abc" === new String("abc"));

a)

true, true

b)

false, true

c)

true, false

d)

false, false