JavaScript Strings & String Methods Quiz
Tackle 75 JavaScript string challenges that cover formatting, slicing, searching, pattern matching, and Unicode-safe manipulation to solidify everyday text-processing skills.
Question 1
What value does this code log?
const word = 'JavaScript'
console.log(word.length)Question 2
What is printed?
const title = 'refactor'
console.log(title.toUpperCase())Question 3
How does trim affect this string?
const message = ' hello world '
console.log(message.trim())Question 4
What boolean does includes return?
const source = 'validation'
console.log(source.includes('lid'))Question 5
What index is produced?
const name = 'mississippi'
console.log(name.indexOf('issi'))Question 6
Which result do you get?
const url = 'https://example.com/page'
console.log(url.lastIndexOf('/'))Question 7
What does slice return?
const phrase = 'component'
console.log(phrase.slice(1, 4))Question 8
How does a negative start affect slice?
const label = 'developer'
console.log(label.slice(-4))Question 9
What substring is produced?
const token = 'submarine'
console.log(token.substring(3, 1))Question 10
What will this log?
const text = 'iteration'
console.log(text.substr(2, 4))Question 11
What array results from this split?
const csv = 'red,green,blue'
console.log(csv.split(','))Question 12
How does the split limit behave?
const path = 'src/utils/helpers.js'
console.log(path.split('/', 2))Question 13
What string do you get back?
const words = ['build', 'test', 'deploy']
console.log(words.join(' -> '))Question 14
What does this template literal output?
const user = 'Nia'
const score = 42
console.log(`${user} scored ${score}`)Question 15
Which character is returned?
const phrase = 'syntax'
console.log(phrase.charAt(2))Question 16
What is logged for an out-of-range index?
const token = 'abc'
console.log(token[5])Question 17
What does repeat return?
const banner = 'hi'
console.log(banner.repeat(3))Question 18
What boolean appears?
const phrase = 'frontend'
console.log(phrase.startsWith('front'))Question 19
Which result do you observe?
const file = 'report.pdf'
console.log(file.endsWith('.pdf'))Question 20
What padded string is produced?
const id = '42'
console.log(id.padStart(5, '0'))Question 21
What does padEnd return?
const code = 'AB'
console.log(code.padEnd(5, '*'))Question 22
How many occurrences are replaced?
const text = 'one two one two'
console.log(text.replace('one', '1'))Question 23
What is the output when using a global regex?
const text = 'one two one two'
console.log(text.replace(/one/g, '1'))Question 24
What happens with replaceAll?
const text = 'foo_bar_foo'
console.log(text.replaceAll('foo', 'baz'))Question 25
What does match return with the global flag?
const text = 'test1 test2'
console.log(text.match(/testd/g))Question 26
What does match return without the global flag?
const text = 'id:123'
console.log(text.match(/id:(d+)/))Question 27
How many entries does matchAll yield?
const text = 'a1 b2'
const results = [...text.matchAll(/(w)(d)/g)]
console.log(results.length)Question 28
What comparison result do you expect?
console.log('apple'.localeCompare('banana'))Question 29
What happens when calling toLowerCase?
const shout = 'LOUD'
console.log(shout.toLowerCase())Question 30
What does String(value) return here?
const value = 100
console.log(String(value))Question 31
What characters are affected by toLocaleUpperCase in Turkish locale?
console.log('i'.toLocaleUpperCase('tr'))Question 32
How does includes handle case?
const text = 'Framework'
console.log(text.includes('frame'))Question 33
What does String.raw output?
console.log(String.raw`hello\nworld`)Question 34
What is the result of concatenating with concat?
const base = 'front'
console.log(base.concat('end'))Question 35
What value comes from valueOf on a string wrapper?
const wrapped = new String('data')
console.log(wrapped.valueOf())Question 36
How many characters result from split without a separator?
console.log('hello'.split())Question 37
What happens when spreading a string?
const chars = Array.from('OK')
console.log(chars)Question 38
What does normalize() return for a precomposed character?
const accented = '\u00E9'
console.log(accented.normalize('NFC'))Question 39
What code point is retrieved?
const smile = '😀'
console.log(smile.codePointAt(0))Question 40
What string does String.fromCodePoint create?
console.log(String.fromCodePoint(9731))Question 41
What number appears?
const phrase = 'ABC'
console.log(phrase.charCodeAt(1))Question 42
What does slice return when the start exceeds the length?
const text = 'abc'
console.log(text.slice(5))Question 43
What does substring with identical arguments return?
const text = 'node'
console.log(text.substring(2, 2))Question 44
How does substr handle a negative start?
const text = 'release'
console.log(text.substr(-3))Question 45
What does this functional replace produce?
const text = 'total: 20'
console.log(text.replace(/(\d+)/, (match) => String(Number(match) * 2)))Question 46
How does padStart behave when using default padding?
const text = '9'
console.log(text.padStart(3))Question 47
What string appears after trimStart?
const text = ' plan'
console.log(text.trimStart())Question 48
What result comes from trimEnd?
const text = 'done '
console.log(text.trimEnd())Question 49
What does match return when there is no match?
const text = 'alpha'
console.log(text.match(/d+/))Question 50
What index does search report?
const text = 'build version 2'
console.log(text.search(/version/))Question 51
What is produced when slicing an empty string?
const text = ''
console.log(text.slice(0, 1))Question 52
How does the second argument of includes shift the search?
const text = 'banana'
console.log(text.includes('na', 3))Question 53
What happens when repeating zero times?
console.log('test'.repeat(0))Question 54
How does the position parameter affect startsWith?
const text = 'metadata'
console.log(text.startsWith('data', 4))Question 55
What does endsWith return when given a length hint?
const text = 'typescript'
console.log(text.endsWith('type', 4))Question 56
What does this multi-line template literal produce?
const output = `Line1
Line2`
console.log(output.split('
').length)Question 57
What array results from splitting on whitespace regex?
const text = 'one two
three'
console.log(text.split(/s+/))Question 58
What does this capture group replacement output?
const text = '2025-11-13'
console.log(text.replace(/(\d{4})-(\d{2})-(\d{2})/, '$2/$3/$1'))Question 59
How does replaceAll behave with a regex literal?
const text = 'aaA'
console.log(text.replaceAll(/a/gi, '*'))Question 60
What structure does match return here?
const text = 'abc123'
const result = text.match(/(abc)(\d+)/)
console.log(result[1])Question 61
How are non-letter characters treated by toUpperCase?
console.log('123!'.toUpperCase())Question 62
What substring is produced by slice with a negative end?
const text = 'pipeline'
console.log(text.slice(0, -1))Question 63
What does substring do with negative indexes?
const text = 'session'
console.log(text.substring(-2, 4))Question 64
Does padEnd change a string already longer than the target?
const text = 'deploy'
console.log(text.padEnd(4, '!'))Question 65
What does localeCompare return for identical strings?
console.log('cache'.localeCompare('cache'))Question 66
What sign does localeCompare return when the first string follows the second?
console.log('zeta'.localeCompare('alpha'))Question 67
What is required when using matchAll?
const text = 'x1 y2'
const iterator = text.matchAll(/(\w)(\d)/)
console.log(Array.isArray(iterator))Question 68
What does includes return when searching for an empty string?
console.log('abc'.includes(''))Question 69
What happens if you pass a fractional count to repeat?
console.log('hi'.repeat(2.5))Question 70
What array results from split with limit zero?
console.log('alpha beta'.split(' ', 0))Question 71
What happens when the substring is not found in replace?
const text = 'metrics'
console.log(text.replace('data', 'info'))Question 72
What does slice return when the end argument is omitted?
const text = 'iteration'
console.log(text.slice(4))Question 73
What result does substring produce when start equals end?
const text = 'state'
console.log(text.substring(3, 3))Question 74
How does split behave with a null separator?
console.log('abc'.split(null))Question 75
What string is created from these char codes?
console.log(String.fromCharCode(72, 105))