最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - why backslash() in a string is giving error in console - Stack Overflow

programmeradmin1浏览0评论

i have a string like

"C:\projects\cisco\iwan_staging_enc\enterprise-network-controller\ui-plugins\iwan"

when i paste into console and press enter, it is giving following error as

Uncaught SyntaxError: Invalid Unicode escape sequence

whats wrong here

Thanks

nageshwar

i have a string like

"C:\projects\cisco\iwan_staging_enc\enterprise-network-controller\ui-plugins\iwan"

when i paste into console and press enter, it is giving following error as

Uncaught SyntaxError: Invalid Unicode escape sequence

whats wrong here

Thanks

nageshwar

Share Improve this question asked Aug 2, 2016 at 13:47 Nageshwar Reddy PandemNageshwar Reddy Pandem 1,0479 silver badges15 bronze badges 4
  • The \backslash is an escape character. – gcampbell Commented Aug 2, 2016 at 13:49
  • means i didnt get you – Nageshwar Reddy Pandem Commented Aug 2, 2016 at 13:50
  • you need to use two backslashes for it to be accepted as a backslash: developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – Arathi Sreekumar Commented Aug 2, 2016 at 13:50
  • @NageshwarReddy developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – gcampbell Commented Aug 2, 2016 at 13:51
Add a ment  | 

2 Answers 2

Reset to default 3

Since backslash is an escape character your string should be modified to:

"C:\\projects\\cisco\\iwan_staging_enc\\enterprise-network-controller\\ui-plugins\\iwan"

Please see: https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Escape_notation

The \u is the start of a unicode escape sequence, in your string you have a \u not followed by four hex numbers which is the format of unicode escape sequence \uxxxx. See

"C:\projects\cisco\iwan_staging_enc\enterprise-network-controller\u0050i-plugins\iwan"

\u0050 id P

Also there there are other types of escapes, so for instance if you had a \n somewhere in there you would get a newline

"C:\new projects\cisco\iwan_staging_enc\enterprise-network-controller\u0050i-plugins\iwan"

So if you do not want avoid these escape sequences escape the \s in the string with a slash before it.

"C:\\projects\\cisco\\iwan_staging_enc\\enterprise-network-controller\\ui-plugins\\iwan"
发布评论

评论列表(0)

  1. 暂无评论