Here is a quick explanation of the expression:
/ # Starting delimiter (so Javascript knows this is a regular expression)
^ # Match the start of the string
\/ # Match a / (needs to be escaped with \)
/ # Ending delimiter
As for the .replace()
function, it takes the string (location.pathname
) and replaces the first parameter (either a string or regular expression) with the second parameter (either a string or a callback function returning a string). This means the backslash at the very beginning of location.pathname
will be replaced with a blank string.