abiA
Deno3y ago
6 replies
abi

Detecting invalid JS strings

Is there any built-in way to "detect" invalid strings?

Here's an example:

// this is an invalid unicode code point
const bad = "\udc11"

// but i can console.log it:
console.log(bad)
// prints: �

// and i can use it in other strings:
const foo = bad + "-" + bad

// but when i try to evaluate it in the repl:
> badAndPrefixed
Unterminated string literal Unknown exception


Some questions:

1. Can I somehow detect "bad" Unicode strings?
2. Why can I console.log it, and what does it do?
3. What happens in the Deno REPL that makes it throw an error?
Was this page helpful?