DEV Community

Discussion on: Escape Sequence in JavaScript - A Few Unused Ones as Well

Collapse
 
lionelrowe profile image
lionel-rowe

I wouldn't call these "character literals", because characters are a different data type from strings in many languages (character is to string as integer is to array of integers). So a character literal would be a syntactical way of expressing a character, such as C's single quote marks or Elixir's ? notation.

Collapse
 
manikbajaj profile image
Manik

Changed the title to Escape Sequence 😀😀 ... Thank you it was a good discussion 👍🙏

Collapse
 
manikbajaj profile image
Manik

I appreciate your point of view. But if you look at resources such as W3C and even various writings about JavaScript in books such as Professional JavaScript for Web Developers they do mention them as character literals and many times as string literals as well. I do understand where you are coming from and the logic behind what you are saying, but this literal syntax also always you to use unicode characters and print them to strings. It's probably that reason they refer to this as Character Literals!

Can't share the image from the book on this comment but here is a post from stack overflow talking about the same
stackoverflow.com/q/28858138/8456836

Collapse
 
lionelrowe profile image
lionel-rowe

That's interesting, but I think that's referring to a different concept again. For example, "A" uses a character literal, but "\x41" doesn't (even though they are the same string). So in the case of escaping newlines, "\n" doesn't use a character literal, whereas

`
`
Enter fullscreen mode Exit fullscreen mode

does.

Thread Thread
 
manikbajaj profile image
Manik

Hmm I would agree to that looking at the logic! How about chnaging the title to escape characters and having a genral approach towads it rather than refering to a specific escape charater that generatds charater literals 👍

Thread Thread
 
lionelrowe profile image
lionel-rowe

Yes, personally I'd call them "escape sequences" (with \ being the "escape character").

Anyway, nice article! 😁

Thread Thread
 
manikbajaj profile image
Manik

Yes agreed 💯