Reputation: 1047
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
Upvotes: 2
Views: 9629
Reputation: 2584
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.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Escape_notation
Upvotes: 3
Reputation: 97707
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"
Upvotes: 1