JavaScript Strings & String Methods Quiz

JavaScript
0 Passed
0% acceptance

Tackle 75 JavaScript string challenges that cover formatting, slicing, searching, pattern matching, and Unicode-safe manipulation to solidify everyday text-processing skills.

75 Questions
~150 minutes
1

Question 1

What value does this code log?

javascript
const word = 'JavaScript'
console.log(word.length)
A
9
B
10
C
11
D
Throws an error
2

Question 2

What is printed?

javascript
const title = 'refactor'
console.log(title.toUpperCase())
A
REFACTOR
B
Refactor
C
refactor
D
undefined
3

Question 3

How does trim affect this string?

javascript
const message = '  hello world  '
console.log(message.trim())
A
hello world
B
hello world
C
hello world
D
hello world
4

Question 4

What boolean does includes return?

javascript
const source = 'validation'
console.log(source.includes('lid'))
A
true
B
false
C
undefined
D
Throws TypeError
5

Question 5

What index is produced?

javascript
const name = 'mississippi'
console.log(name.indexOf('issi'))
A
1
B
2
C
4
D
-1
6

Question 6

Which result do you get?

javascript
const url = 'https://example.com/page'
console.log(url.lastIndexOf('/'))
A
5
B
7
C
18
D
22
7

Question 7

What does slice return?

javascript
const phrase = 'component'
console.log(phrase.slice(1, 4))
A
com
B
omp
C
mpo
D
ponent
8

Question 8

How does a negative start affect slice?

javascript
const label = 'developer'
console.log(label.slice(-4))
A
deve
B
lope
C
oper
D
velo
9

Question 9

What substring is produced?

javascript
const token = 'submarine'
console.log(token.substring(3, 1))
A
sub
B
ub
C
bm
D
10

Question 10

What will this log?

javascript
const text = 'iteration'
console.log(text.substr(2, 4))
A
erat
B
tera
C
rati
D
iter
11

Question 11

What array results from this split?

javascript
const csv = 'red,green,blue'
console.log(csv.split(','))
A
["red,green,blue"]
B
["red", "green", "blue"]
C
["red", "green"]
D
[]
12

Question 12

How does the split limit behave?

javascript
const path = 'src/utils/helpers.js'
console.log(path.split('/', 2))
A
["src", "utils", "helpers.js"]
B
["src", "utils"]
C
["src"]
D
["helpers.js"]
13

Question 13

What string do you get back?

javascript
const words = ['build', 'test', 'deploy']
console.log(words.join(' -> '))
A
build,test,deploy
B
build -> test -> deploy
C
build -> test
D
deploy -> test -> build
14

Question 14

What does this template literal output?

javascript
const user = 'Nia'
const score = 42
console.log(`${user} scored ${score}`)
A
Nia scored 42
B
${user} scored ${score}
C
Nia scored ${score}
D
undefined
15

Question 15

Which character is returned?

javascript
const phrase = 'syntax'
console.log(phrase.charAt(2))
A
s
B
y
C
n
D
t
16

Question 16

What is logged for an out-of-range index?

javascript
const token = 'abc'
console.log(token[5])
A
an empty string
B
undefined
C
0
D
Throws RangeError
17

Question 17

What does repeat return?

javascript
const banner = 'hi'
console.log(banner.repeat(3))
A
hihihi
B
hi3
C
hhh
D
Throws TypeError
18

Question 18

What boolean appears?

javascript
const phrase = 'frontend'
console.log(phrase.startsWith('front'))
A
true
B
false
C
undefined
D
Throws Error
19

Question 19

Which result do you observe?

javascript
const file = 'report.pdf'
console.log(file.endsWith('.pdf'))
A
true
B
false
C
undefined
D
Throws Error
20

Question 20

What padded string is produced?

javascript
const id = '42'
console.log(id.padStart(5, '0'))
A
42000
B
042
C
00042
D
42
21

Question 21

What does padEnd return?

javascript
const code = 'AB'
console.log(code.padEnd(5, '*'))
A
AB***
B
***AB
C
AB*
D
AB
22

Question 22

How many occurrences are replaced?

javascript
const text = 'one two one two'
console.log(text.replace('one', '1'))
A
1 two one two
B
1 two 1 two
C
one two one two
D
Throws Error
23

Question 23

What is the output when using a global regex?

javascript
const text = 'one two one two'
console.log(text.replace(/one/g, '1'))
A
1 two 1 two
B
1 two one two
C
one two one two
D
Throws Error
24

Question 24

What happens with replaceAll?

javascript
const text = 'foo_bar_foo'
console.log(text.replaceAll('foo', 'baz'))
A
baz_bar_baz
B
baz_bar_foo
C
foo_bar_foo
D
Throws Error
25

Question 25

What does match return with the global flag?

javascript
const text = 'test1 test2'
console.log(text.match(/testd/g))
A
["test1", "test2"]
B
["test1"]
C
null
D
Throws Error
26

Question 26

What does match return without the global flag?

javascript
const text = 'id:123'
console.log(text.match(/id:(d+)/))
A
["id:123", "123"]
B
["id:123"]
C
123
D
null
27

Question 27

How many entries does matchAll yield?

javascript
const text = 'a1 b2'
const results = [...text.matchAll(/(w)(d)/g)]
console.log(results.length)
A
1
B
2
C
3
D
Throws TypeError
28

Question 28

What comparison result do you expect?

javascript
console.log('apple'.localeCompare('banana'))
A
-1 or a negative number
B
0
C
1 or a positive number
D
Throws Error
29

Question 29

What happens when calling toLowerCase?

javascript
const shout = 'LOUD'
console.log(shout.toLowerCase())
A
loud
B
LOUD
C
Loud
D
undefined
30

Question 30

What does String(value) return here?

javascript
const value = 100
console.log(String(value))
A
100
B
"100"
C
[object Number]
D
Throws Error
31

Question 31

What characters are affected by toLocaleUpperCase in Turkish locale?

javascript
console.log('i'.toLocaleUpperCase('tr'))
A
I
B
İ
C
i
D
Throws Error
32

Question 32

How does includes handle case?

javascript
const text = 'Framework'
console.log(text.includes('frame'))
A
true
B
false
C
undefined
D
Throws Error
33

Question 33

What does String.raw output?

javascript
console.log(String.raw`hello\nworld`)
A
hello world
B
hello\nworld
C
helloworld
D
Throws Error
34

Question 34

What is the result of concatenating with concat?

javascript
const base = 'front'
console.log(base.concat('end'))
A
frontend
B
front
C
endfront
D
Throws Error
35

Question 35

What value comes from valueOf on a string wrapper?

javascript
const wrapped = new String('data')
console.log(wrapped.valueOf())
A
[object String]
B
data
C
Throws Error
D
undefined
36

Question 36

How many characters result from split without a separator?

javascript
console.log('hello'.split())
A
["hello"]
B
["h", "e", "l", "l", "o"]
C
[]
D
Throws Error
37

Question 37

What happens when spreading a string?

javascript
const chars = Array.from('OK')
console.log(chars)
A
["OK"]
B
["O", "K"]
C
[["O"], ["K"]]
D
Throws Error
38

Question 38

What does normalize() return for a precomposed character?

javascript
const accented = '\u00E9'
console.log(accented.normalize('NFC'))
A
\u0065\u0301
B
\u00E9
C
e
D
Throws Error
39

Question 39

What code point is retrieved?

javascript
const smile = '😀'
console.log(smile.codePointAt(0))
A
55357
B
128512
C
0
D
Throws Error
40

Question 40

What string does String.fromCodePoint create?

javascript
console.log(String.fromCodePoint(9731))
A
B
C
?
D
Throws Error
41

Question 41

What number appears?

javascript
const phrase = 'ABC'
console.log(phrase.charCodeAt(1))
A
65
B
66
C
67
D
1
42

Question 42

What does slice return when the start exceeds the length?

javascript
const text = 'abc'
console.log(text.slice(5))
A
B
c
C
Throws Error
D
undefined
43

Question 43

What does substring with identical arguments return?

javascript
const text = 'node'
console.log(text.substring(2, 2))
A
B
de
C
no
D
Throws Error
44

Question 44

How does substr handle a negative start?

javascript
const text = 'release'
console.log(text.substr(-3))
A
rel
B
ase
C
lea
D
45

Question 45

What does this functional replace produce?

javascript
const text = 'total: 20'
console.log(text.replace(/(\d+)/, (match) => String(Number(match) * 2)))
A
total: 40
B
total: 20
C
40
D
Throws Error
46

Question 46

How does padStart behave when using default padding?

javascript
const text = '9'
console.log(text.padStart(3))
A
009
B
9
C
9
D
Throws Error
47

Question 47

What string appears after trimStart?

javascript
const text = '   plan'
console.log(text.trimStart())
A
plan
B
plan
C
plan
D
Throws Error
48

Question 48

What result comes from trimEnd?

javascript
const text = 'done   '
console.log(text.trimEnd())
A
done
B
done
C
done
D
Throws Error
49

Question 49

What does match return when there is no match?

javascript
const text = 'alpha'
console.log(text.match(/d+/))
A
[]
B
null
C
Throws Error
D
50

Question 50

What index does search report?

javascript
const text = 'build version 2'
console.log(text.search(/version/))
A
0
B
6
C
12
D
-1
51

Question 51

What is produced when slicing an empty string?

javascript
const text = ''
console.log(text.slice(0, 1))
A
B
null
C
0
D
Throws Error
52

Question 52

How does the second argument of includes shift the search?

javascript
const text = 'banana'
console.log(text.includes('na', 3))
A
true
B
false
C
undefined
D
Throws Error
53

Question 53

What happens when repeating zero times?

javascript
console.log('test'.repeat(0))
A
B
test
C
Throws Error
D
undefined
54

Question 54

How does the position parameter affect startsWith?

javascript
const text = 'metadata'
console.log(text.startsWith('data', 4))
A
true
B
false
C
Throws Error
D
undefined
55

Question 55

What does endsWith return when given a length hint?

javascript
const text = 'typescript'
console.log(text.endsWith('type', 4))
A
true
B
false
C
Throws Error
D
undefined
56

Question 56

What does this multi-line template literal produce?

javascript
const output = `Line1
Line2`
console.log(output.split('
').length)
A
1
B
2
C
Throws Error
D
0
57

Question 57

What array results from splitting on whitespace regex?

javascript
const text = 'one	 two
three'
console.log(text.split(/s+/))
A
["one", "two", "three"]
B
["one", "two three"]
C
["one ", "two three"]
D
["one two three"]
58

Question 58

What does this capture group replacement output?

javascript
const text = '2025-11-13'
console.log(text.replace(/(\d{4})-(\d{2})-(\d{2})/, '$2/$3/$1'))
A
11/13/2025
B
2025/11/13
C
13/11/2025
D
Throws Error
59

Question 59

How does replaceAll behave with a regex literal?

javascript
const text = 'aaA'
console.log(text.replaceAll(/a/gi, '*'))
A
***
B
**A
C
aaA
D
Throws TypeError
60

Question 60

What structure does match return here?

javascript
const text = 'abc123'
const result = text.match(/(abc)(\d+)/)
console.log(result[1])
A
abc
B
123
C
null
D
Throws Error
61

Question 61

How are non-letter characters treated by toUpperCase?

javascript
console.log('123!'.toUpperCase())
A
123!
B
123
C
!123
D
Throws Error
62

Question 62

What substring is produced by slice with a negative end?

javascript
const text = 'pipeline'
console.log(text.slice(0, -1))
A
pipelin
B
pipeline
C
e
D
63

Question 63

What does substring do with negative indexes?

javascript
const text = 'session'
console.log(text.substring(-2, 4))
A
sess
B
session
C
Throws Error
D
64

Question 64

Does padEnd change a string already longer than the target?

javascript
const text = 'deploy'
console.log(text.padEnd(4, '!'))
A
deploy
B
deploy!!!!
C
dep!
D
Throws Error
65

Question 65

What does localeCompare return for identical strings?

javascript
console.log('cache'.localeCompare('cache'))
A
0
B
1
C
-1
D
Throws Error
66

Question 66

What sign does localeCompare return when the first string follows the second?

javascript
console.log('zeta'.localeCompare('alpha'))
A
A negative number
B
Zero
C
A positive number
D
Throws Error
67

Question 67

What is required when using matchAll?

javascript
const text = 'x1 y2'
const iterator = text.matchAll(/(\w)(\d)/)
console.log(Array.isArray(iterator))
A
true
B
false
C
Throws Error
D
undefined
68

Question 68

What does includes return when searching for an empty string?

javascript
console.log('abc'.includes(''))
A
true
B
false
C
undefined
D
Throws Error
69

Question 69

What happens if you pass a fractional count to repeat?

javascript
console.log('hi'.repeat(2.5))
A
hihi
B
Throws RangeError
C
hi
D
undefined
70

Question 70

What array results from split with limit zero?

javascript
console.log('alpha beta'.split(' ', 0))
A
[]
B
["alpha"]
C
["alpha", "beta"]
D
[""]
71

Question 71

What happens when the substring is not found in replace?

javascript
const text = 'metrics'
console.log(text.replace('data', 'info'))
A
metrics
B
info
C
Throws Error
D
metricsinfo
72

Question 72

What does slice return when the end argument is omitted?

javascript
const text = 'iteration'
console.log(text.slice(4))
A
ration
B
iter
C
tion
D
73

Question 73

What result does substring produce when start equals end?

javascript
const text = 'state'
console.log(text.substring(3, 3))
A
B
t
C
te
D
Throws Error
74

Question 74

How does split behave with a null separator?

javascript
console.log('abc'.split(null))
A
["abc"]
B
["a", "b", "c"]
C
Throws Error
D
["", "", ""]
75

Question 75

What string is created from these char codes?

javascript
console.log(String.fromCharCode(72, 105))
A
Hi
B
hi
C
H
D
Throws Error

QUIZZES IN JavaScript