New course! Every coder should learn Generative AI!
Try a free lesson0
\ in strings is used to escape char (encode invisible char from a visible pair or 'protect' them)... so next char to it is interpreted un a special manner. For example:
'\n' is substitued with the char code 10 (new line)
'I\'m' is substitued with a quote (if we don't protect it, js will think that your string end just before the m.
So, \ having a special meaning, if you want one of it in a string literal, you must protect it as a quote (double it for displaying only one).
The fun come when we are dealing with string literal targeted to store regular expression sources: we often need to triple or qyadruple them, and it commonly turn it to something unreadable :P