Question Bank

String Basics Quiz

Difficulty: Easy

Three short prompts on JavaScript string immutability, slicing, and char codes. Good warm-up before tackling sliding-window or palindrome problems.

Question Bank
/

String Basics Quiz

String Basics Quiz

Three short prompts on JavaScript string immutability, slicing, and char codes. Good warm-up before tackling sliding-window or palindrome problems.

Question Bank
Easy
JavaScript
3 questions
strings
data-structures
quiz
fundamentals

286 views

2

What does this snippet print and why? Explain whether s[0] = 'X' would mutate s.

Examples

Example 1:

Input: s = 'hello'; then s[0] = 'X'; print s, s.length, s.toUpperCase(), s
Output: hello, 5, HELLO, hello
Explanation: Strings are immutable in JavaScript, so s[0] = 'X' is silently ignored (or throws in strict mode). toUpperCase returns a new string without mutating s.