MCQs on Working with Strings and Numbers | JavaScript

“Working with Strings and Numbers” dives into the fundamentals of string and number manipulation in programming. Understanding string methods, template literals, number parsing, and basic math operations is crucial for data handling and creating dynamic applications. Below are 30 carefully curated multiple-choice questions, divided by topic for a focused learning experience.


String Methods

  1. Which method returns the length of a string?
    • A) toUpperCase()
    • B) toLowerCase()
    • C) length
    • D) indexOf()
  2. Which method would you use to convert a string to uppercase?
    • A) toUpperCase()
    • B) toLowerCase()
    • C) charAt()
    • D) slice()
  3. Which method converts a string to lowercase?
    • A) concat()
    • B) toLowerCase()
    • C) includes()
    • D) toUpperCase()
  4. What does the trim() method do to a string?
    • A) Removes all characters.
    • B) Adds spaces at the beginning and end.
    • C) Removes whitespace from both ends.
    • D) Replaces spaces with underscores.
  5. What is the result of "hello".charAt(1)?
    • A) h
    • B) e
    • C) l
    • D) o
  6. Which method can check if a string starts with a specified substring?
    • A) includes()
    • B) startsWith()
    • C) indexOf()
    • D) slice()
  7. What will "JavaScript".indexOf("Script") return?
    • A) 4
    • B) 0
    • C) 5
    • D) 6
  8. Which method would you use to split a string into an array?
    • A) split()
    • B) slice()
    • C) trim()
    • D) toLowerCase()
  9. What does the replace() method do in a string?
    • A) Converts the string to lowercase.
    • B) Replaces the first occurrence of a substring with a new string.
    • C) Removes whitespace from both ends.
    • D) Changes the entire string.
  10. Which of the following will capitalize only the first letter of the string "hello"?
    • A) "hello".toUpperCase()
    • B) "hello".charAt(0).toUpperCase() + "hello".slice(1)
    • C) "hello".toUpperCase() + "hello".slice(1)
    • D) "hello".slice(1)

Template Literals and String Interpolation

  1. Which symbol is used to denote template literals in JavaScript?
    • A) '
    • B) "
    • C) {}
    • D) `
  2. What will the output be for const name = "Alice"; const message = Hello, ${name}!;?
    • A) Hello, ${name}!
    • B) Hello, Alice!
    • C) Hello Alice!
    • D) ${name}, Hello!
  3. Which is a key feature of template literals?
    • A) String methods
    • B) Interpolation of variables
    • C) Adding numbers
    • D) Changing case
  4. What is the output of `The sum is: ${5 + 10}`?
    • A) The sum is: 15
    • B) The sum is: ${5 + 10}
    • C) The sum is 5 + 10
    • D) The sum: 15
  5. How can multi-line strings be created in JavaScript?
    • A) Using + between strings
    • B) With single quotes
    • C) With double quotes
    • D) Using template literals

Number Methods

  1. What is the output of parseInt("20.5")?
    • A) 20
    • B) 20.5
    • C) NaN
    • D) undefined
  2. Which method can convert a string to a float number?
    • A) parseInt()
    • B) Number()
    • C) parseFloat()
    • D) toFixed()
  3. What is the result of isNaN("Hello")?
    • A) true
    • B) false
    • C) NaN
    • D) undefined
  4. Which method can detect if a value is not a number?
    • A) parseInt()
    • B) Number()
    • C) isNaN()
    • D) toString()
  5. What will Number("50") + Number("10.5") return?
    • A) 60
    • B) 60.5
    • C) NaN
    • D) 510.5
  6. Which of the following converts the string "123" to an integer?
    • A) parseInt("123")
    • B) parseFloat("123")
    • C) Number("123")
    • D) All of the above
  7. What will parseFloat("10.99abc") return?
    • A) 10.99
    • B) NaN
    • C) 10
    • D) abc
  8. Which of the following will return NaN?
    • A) Number("123a")
    • B) parseInt("123")
    • C) parseFloat("123.45")
    • D) Number("123")
  9. Which method rounds a number to the nearest integer?
    • A) parseInt()
    • B) parseFloat()
    • C) Math.round()
    • D) Number()
  10. Which of these methods can convert a number to a string?
    • A) parseInt()
    • B) Number()
    • C) toString()
    • D) isNaN()

Basic Math Object Methods

  1. What does Math.max(3, 7, 1, 5) return?
    • A) 1
    • B) 3
    • C) 5
    • D) 7
  2. Which of the following methods will return the smallest number in a list?
    • A) Math.round()
    • B) Math.ceil()
    • C) Math.min()
    • D) Math.max()
  3. Which method returns the square root of a number?
    • A) Math.sqrt()
    • B) Math.pow()
    • C) Math.abs()
    • D) Math.floor()
  4. What is the result of Math.floor(4.7)?
    • A) 4
    • B) 5
    • C) 4.7
    • D) NaN
  5. Which method rounds a number up to the nearest integer?
    • A) Math.ceil()
    • B) Math.floor()
    • C) Math.round()
    • D) parseInt()

Answers

QnoAnswer
1C) length
2A) toUpperCase()
3B) toLowerCase()
4C) Removes whitespace from both ends
5B) e
6B) startsWith()
7A) 4
8A) split()
9B) Replaces the first occurrence of a substring with a new string
10B) “hello”.charAt(0).toUpperCase() + “hello”.slice(1)
11D) `
12B) Hello, Alice!
13B) Interpolation of variables
14A) The sum is: 15
15D) Using template literals
16A) 20
17C) parseFloat()
18A) true
19C) isNaN()
20B) 60.5
21D) All of the above
22A) 10.99
23A) Number(“123a”)
24C) Math.round()
25C) toString()
26D) 7
27C) Math.min()
28A) Math.sqrt()
29A) 4
30A) Math.ceil()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top