Frequently Asked Questions

Feb 21, 2024 - 01:05am

 [F] Frequently Asked Questions  / Operational Questions  / Macros and Templates  / WCJS (Server Side JavaScript)  /

Double quotes and single

Rate This FAQ
 (Not yet rated)

Created On: 5 Jun 2002 10:30 am
Last Edited: 5 Jun 2002 10:30 am

Question Printer Friendly

Double quotes and single quotes are used differently in WCTL and WCJS

Answer

Double-quotes
  (") and single-quotes (') serve different purposes in WCTL and WCJS.

In WCJS, double-quotes
  and single-quotes are used interchangeably, as long as they are used in pairs.
  For example, the following are both equivalent:


var
    a = "Web Crossing rocks!";
var a = 'Web Crossing rocks!';


In WCJS if you
  want to embed a double-quote inside a character string, the easiest thing to
  do is simply enclose the string in single-quotes. Experienced JavaScript programmers
  do this all the time for creating strings with embedded HTML tags, as in:


var
    msg = '<img src="file.gif">';


In WCTL you would
  embed a double-quote in a character string by using two double-quotes. That
  is, the string """" contains one double quote. The equivalent
  HTML tag saved in WCTL would look like:


%%
    set msg "<img src=""file.gif"">" %%


In WCTL double-quotes
  are used to quote character strings and single-quotes are used to quote single
  characters, which are considered fundamentally to be different.

That is, in WCJS
  the express 'A' == "A" is true but in WCTL 'A' ==
  "A"
is false. In WCJS they are the same string, but in
  WCTL 'A' is a character and "A" is a string containing one character.

In WCTL you can
  get the character code for a character with an expression like:


%%
    'A' %%


which outputs 65,
  the ASCII code for the character A.

You can also get
  the character code quite easily in WCJS, using the String.charCodeAt() method, which returns the Unicode value (an integer between 0 and 65535). For
  example, the following expression:


%%
    "'A'.charCodeAt(0)".jsEval %%


also outputs 65.