What will be the output of the following code

let userName = "JAVASCRIPT";
userName.toLowerCase();
console.log(userName);

Answer:

  • JAVASCRIPT (in upper case)

Explanation:

  • In javascript strings are immutable. That means you cannot change the original string in the memory. If you want to change the caps of string or apply some method to the string, you must assign it to another variable.
  • The below code will work properly
let userName = "JAVASCRIPT";
const lowerUserName = userName.toLowerCase();
console.log(lowerUserName);