π§ Transforming Text with toUpperCase() in JavaScript
π Understanding toUpperCase()
In JavaScript, the toUpperCase()
method is used to convert all lowercase letters in a string to uppercase. This is helpful when you want to standardize text or make words stand out.
π§Ύ Syntax
string.toUpperCase();
π‘ Example
let originalString = "Hello, world!";
let uppercaseString = originalString.toUpperCase();
console.log(uppercaseString); // Output: HELLO, WORLD!
π Key Points
- Case Sensitivity: Only lowercase characters are affected.
- Immutable: It returns a new string; the original stays the same.
- Non-Letters: Numbers and symbols are not changed.
π Quick Quiz
Quiz 1
Which code correctly converts "hello, world!"
to uppercase?
- A.
console.log("hello, world!".toUpperCase());
- B.
console.log("hello, world!".toLowerCase());
- C.
console.log("hello, world!".charAt(0).toUpperCase());
- D.
console.log("hello, world!".replace("hello", "HELLO"));
Quiz 2
Does toUpperCase()
modify the original string?
- A. Yes, it modifies the original string.
- B. No, it returns a new string with the converted characters.
- C. It depends on the browser.
- D. It only modifies strings that are stored in variables.
π¬ Type your answers in the comment section!