Search code examples
javascriptreact-nativerealm

' VS " in javascript


I am using Realm in react native.

Here's my code.

 const filter = "t BEGINSWITH 'A'";
 const markers = realm.objects(Town.schema.name).filtered(filter);

The above code is not working. But if I change the filter code like this:

 const filter = 't BEGINSWITH "A"';

Then it works charm.

What's the difference between ' and " in javascript?

Thanks for your time.


Solution

  • There is no difference between ' and " in JavaScript (other than the obvious that ' may exist escaped inside "-quoted strings and vice versa).

    There apparently is a difference between ' and " in the Realm query language: namely, that double-quotes must be used to represent strings.

    See the Realm documentation on filtering which uses double-quotes for strings with BEGINSWITH:

    let tanDogs = dogs.filtered('color = "tan" AND name BEGINSWITH "B"');