user1477388
user1477388

Reputation: 21440

Javascript syntax identification

Writing a regular expression, I found this code:

JSON.stringify(e.model.ProcedureDate).replace(/\"/g, '');

Why does /\"/g work without being quoted? It isn't a string, and from what I gather, javascript doesn't have literals... What would you call the text passed to .replace()?

Upvotes: 0

Views: 26

Answers (2)

Aprillion
Aprillion

Reputation: 22340

It is a regular expression literal, equivalent to:

new RegExp('\\"', 'g')

in the same way as [] is equivalent to new Array(0).

Upvotes: 2

Mike Cluck
Mike Cluck

Reputation: 32521

Javascript has regular expression literals. That's an example of one.

Upvotes: 2

Related Questions