WorksheetsJavaScript Numbers and Strings – MCQs
Total questions: 30
Worksheet time: 15mins
What is the output of the following code?
let x = 10;
let y = "5";
console.log(x + y);
15
105
10 + 5
Error
Which of the following methods converts a number to a string?
toNumber()
toText()
toString()
parseInt()
What will be the output?
console.log(Number("123"));
"123"
123
NaN
undefined
What is the output of:
console.log(parseInt("12.34"));
12.34
12
13
NaN
Which method converts a number into an exponential notation?
toExponential()
toPrecision()
toFixed()
toLocaleString()
What is the output of:
console.log(isNaN("Hello"));
true
false
"Hello"
NaN
What is the output of:
console.log((0.1 + 0.2).toFixed(2));
0.3
"0.30"
0.30
"0.3"
Which method returns NaN if the value cannot be converted into a number?
parseInt()
Number()
toNumber()
eval()
What is the result of:
console.log(Math.floor(4.7));
4.7
4
5
NaN
What does Math.random() return?
A random integer
A random decimal between 0 and 1
A random number between 1 and 10
Always 0
What is the output of:
console.log("Hello".length);
4
5
6
Error
Which method joins two strings?
append()
concat()
combine()
join()
What will the following code display?
let str = "JavaScript";
console.log(str.toUpperCase());
javascript
JAVASCRIPT
JavaScript
Error
What is the output of:
"Hello World".toLowerCase();
"HELLO WORLD"
"hello world"
"hello World"
"Hello world"
Which of the following methods removes whitespace from both ends of a string?
`trim()`
`slice()`
`replace()`
`split()`
What is the output?
let str = "JavaScript";
console.log(str.charAt(4));
"S"
"a"
"s"
"c"
What will this return?
let text = "Hello, World!";
console.log(text.indexOf("World"));
-1
6
7
Error
What is the result of:
"Hello".replace("H", "J");
"Jello"
"HJello"
"HelloJ"
Error
What will be the output of:
"apple,banana,kiwi".split(",");
`apple,banana,kiwi`
`["apple", "banana", "kiwi"]`
"apple banana kiwi"
`["apple banana kiwi"]`
What is the output?
let str = "JavaScript";
console.log(str.slice(4, 10));
"Script"
"JavaSc"
"vaScri"
"aScrip"
What will be the output?
console.log(0.1 + 0.2 === 0.3);
true
false
NaN
undefined
What is the output?
console.log(Math.max(10, 20, "30"));
"30"
30
NaN
undefined
What does the following log?
console.log(parseInt("08"));
8
0
NaN
Error
What is the output?
console.log(isFinite("200"));
true
false
NaN
undefined
What does the following code output?
console.log(Math.round(4.5));
console.log(Math.floor(4.9));
console.log(Math.ceil(4.1));
4, 4, 4
5, 4, 5
5, 5, 5
4, 5, 4
What is the output?
console.log("5" + 3 + 2);
"532"
"10"
10
"55"
What is the result?
console.log("5" - 3 + 2);
532
4
2
NaN
What will this print?
let text = "Hello World";
console.log(text.substring(6, 11));
console.log(text.slice(-5));
"World", "World"
"World", "Hello"
"Hello", "World"
"World", "rld"
What is the output?
let str = "JavaScript";
str[0] = "Y";
console.log(str);
"YavaScript"
"JavaScript"
Error
undefined
What is the result?
console.log("abc" == new String("abc"));
console.log("abc" === new String("abc"));
true, true
false, true
true, false
false, false
