WiLLyxVKei
WiLLyxVKei

Reputation: 113

Differences with CFscript calling value methods

I'm working with ColdFusion and CFScript. At the moment I've no problems, but noticed that I can call values in 3 ways:

  1. Value
  2. 'Value'
  3. '#Value#'

What are the differences between them? Thanks in advance!

Upvotes: 0

Views: 51

Answers (1)

Alex
Alex

Reputation: 7833

  1. Value

CF searches for a variable called Value (case insensitive) starting with the VARIABLES scope and then progressing through other scopes (like URL and FORM), stopping at the first variable found.

  1. 'Value'

A literal string with the characters V, a, l, u and e.

  1. '#Value#'

A string where Value will be evaluated (CF evalautes stuff between #). If the variable Value (case insensitive) is a so called simple value, the variable will be cast to a string. Otherwise, an exception is thrown since non-simple (ie complex ) values are not automatically cast as strings. This is basically equivalent to '' & Value & '' (string concatenation).


Value = 'Hello World !!';

writeOutput(Value);
>> Hello World !!

writeOutput('Value');
>> Value

writeOutput('#Value#');
>> Hello World !!

writeOutput( evaluate('Value') );
>> Hello World !!

Upvotes: 2

Related Questions