JavaScript Uppercase

πŸ” 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!


<
Previous Post
πŸ” Mastering indexOf in JavaScript: What Every Developer Should Know
>
Next Post
🧠 Debugging Made Simple with console.table