Predict the output of the following javascript code
const string = "hello world";
const result = string.replace(/l/g, "");
console.log(result);
Quiz Explanation
This JavaScript code defines a constant variable string
with the value "hello world"
. Then, it uses the replace()
method on the string to replace all occurrences of the letter 'l' (specified by the regular expression /l/g
) with an empty string ""
.
So, the output of this code will be the string "heo word"
, which is the original string with all occurrences of the letter 'l' removed.