Skip to content

Instantly share code, notes, and snippets.

@Ovilia
Created February 14, 2013 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ovilia/4951288 to your computer and use it in GitHub Desktop.
Save Ovilia/4951288 to your computer and use it in GitHub Desktop.
JavaScript escape related string
// In JavaScript string, you don't need to escape /
var a = "a/b"; // will give "a/b"
// But if you use \, it can be escaped
var b = "a\/b"; // will also give "a/b"
// While \ should always be escaped
var c = "a\b"; // will give "a" since \b means a backspace,
// which does nothing special here
// The right way for a \
var d = "a\\b"; // will give "a\b" as expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment