What two keys mean in JavaScript


I understand the "===" that tests value and type, different from "==" that tests only value, however I did not understand the double key, type: {{alguma_coisa}} , for example in a JavaScript that I own, has something like this:

mozL10n.get('page_of', {pageCount: pagesCount}, 'de {{pageCount}}');

Is there a need for both keys?

asked by anonymous 03.11.2015 / 11:57

2 answers


This is specific to this Non-standard API . Avoid using it. This is a placeholder . It is using to produce a string interpolation, even though it uses a simpler form. It's a lot like the {0} used in C #, but a bit better because the expression can be used inside the string , as in #. This expression will be evaluated and its result will be printed in this location.

The double keys were chosen to avoid any ambiguity. It could be anything else. The important thing is to have some character that marks the beginning and end of the expression and that is something little used in normal texts, to avoid having to escape and to print this of normal form.

03.11.2015 / 12:04

In this example:

var a = {};

It is used only to initialize an object with no value in it.

In your Example:

mozL10n.get('page_of', {pageCount: pagesCount}, 'de {{pageCount}}');

It is used as a template pattern for identifying values that will be modified, this is not a javascript convention but an API convention.

03.11.2015 / 12:06