Variables, Data Types & Scopes
Data types
ColdFusion is dynamically typed. Variables are created on assignment and their type is inferred at runtime — no int, String, or var declarations required.
| Type | Example | Notes |
|---|---|---|
| String | "Hello" | Immutable; & concatenates |
| Numeric | 42, 3.14 | Integer and float unified |
| Boolean | true, false, yes, no | yes/no are aliases |
| Date | now(), "2026-09-03" | Rich date/time functions built in |
| Array | [1, 2, 3] | 1-based index |
| Struct | {name: "Alex", age: 30} | Key-value map; keys case-insensitive |
| Query | result of cfquery / queryExecute() | Tabular result set |
![[object Object]](/content/files/courses/ColdFusion-2025-Foundations-5151cba6/module-1/3.lesson-variables-scopes/__static__/cfml-data-types-overview-v1.png?v=1789774489337)
CFML's six core data types — dynamically inferred at runtime, no explicit type declarations needed.
Activity: Click the Terminal tab in your lab. Once the terminal is open, copy and paste the script below to create data_types.cfm and explore all six data types:
sudo tee /opt/coldfusion2025/cfusion/wwwroot/data_types.cfm << 'EOF'
<cfscript>
// String
myString = "Hello ColdFusion";
writeOutput("<strong>String:</strong> " & myString & "<br>");
// Numeric
myInt = 42;
myFloat = 3.14;
writeOutput("<strong>Numeric:</strong> " & myInt & " / " & myFloat & "<br>");
// Boolean
isActive = true;
writeOutput("<strong>Boolean:</strong> " & isActive & "<br>");
// Date
today = now();
writeOutput("<strong>Date:</strong> " & dateFormat(today, "yyyy-mm-dd") & "<br>");
// Array
fruits = ["apple", "banana", "cherry"];
writeOutput("<strong>Array[1]:</strong> " & fruits[1] & "<br>");
// Struct
person = {name: "Alex", age: 30};
writeOutput("<strong>Struct:</strong> " & person.name & " is " & person.age & "<br>");
</cfscript>
EOF
Open /data_types.cfm in the ColdFusion 2025 browser tab (right-click → Open Link in New Tab, then change the path). Or from the Terminal:
curl -s http://localhost:8500/data_types.cfm
![[object Object]](/content/files/courses/ColdFusion-2025-Foundations-5151cba6/module-1/3.lesson-variables-scopes/__static__/browser-output-data-types-v1.png?v=1789774489337)
All six data types rendered — each line shows the type name and its value.
Variable scopes
ColdFusion organises variables into named scopes. Every scope has a different lifetime and visibility.
| Scope | Prefix | Lifetime | Typical use |
|---|---|---|---|
variables | variables. | Single request | Default local scope for a page/CFC |
url | url. | Single request | Query-string parameters |
form | form. | Single request | POST form fields |
request | request. | Single request | Pass data between included files |
session | session. | User session | Per-user state (cart, login) |
application | application. | App lifetime | Shared config, counters |
server | server. | Server lifetime | Rarely written; read CF/Lucee version |
The variables scope is the default when you omit a prefix. Always prefix session.* and application.* explicitly.
![[object Object]](/content/files/courses/ColdFusion-2025-Foundations-5151cba6/module-1/3.lesson-variables-scopes/__static__/cfml-scope-lifetimes-v1.png?v=1789774489337)
Scope lifetimes compared — request-scoped variables are cheapest; application-scoped variables persist for the life of the process.
Activity: Still in the Terminal tab, copy and paste the script below to create scopes.cfm and demonstrate the variables scope explicitly:
sudo tee /opt/coldfusion2025/cfusion/wwwroot/scopes.cfm << 'EOF'
<cfscript>
// variables scope — explicit prefix
variables.name = "Alex";
variables.course = "ColdFusion 2025";
writeOutput("<strong>variables.name:</strong> " & variables.name & "<br>");
writeOutput("<strong>variables.course:</strong> " & variables.course & "<br>");
// url scope — reads ?name= from the query string
urlName = url.name ?: "no name passed";
writeOutput("<strong>url.name:</strong> " & urlName & "<br>");
</cfscript>
EOF
Open /scopes.cfm in the browser to confirm the variables scope output:
curl -s http://localhost:8500/scopes.cfm
![[object Object]](/content/files/courses/ColdFusion-2025-Foundations-5151cba6/module-1/3.lesson-variables-scopes/__static__/browser-output-scopes-v1.png?v=1789774489337)
scopes.cfm with no query string — variables.* values are set, url.name falls back to the default.
Now verify that the variables. prefix is used explicitly in the file:
URL scope
Pass a query-string parameter and read it back with url.name:
curl -s "http://localhost:8500/scopes.cfm?name=TestUser"
# Expected: url.name: TestUser
Or in the browser, append ?name=TestUser to the URL:
https://<your-session-id>.iximiuz.com/scopes.cfm?name=TestUser
![[object Object]](/content/files/courses/ColdFusion-2025-Foundations-5151cba6/module-1/3.lesson-variables-scopes/__static__/browser-output-scopes-url-v1.png?v=1789774489337)
With ?name=TestUser appended, url.name resolves to TestUser instead of the default.
Scope resolution order
![[object Object]](/content/files/courses/ColdFusion-2025-Foundations-5151cba6/module-1/3.lesson-variables-scopes/__static__/cfml-scope-resolution-order-v1.png?v=1789774489337)
When you omit a scope prefix, CF walks this resolution chain top-to-bottom — always prefix to be explicit.
When you write just name without a prefix, ColdFusion checks scopes in this order:
local(inside a CFC function)argumentsthreadquery(inside a<cfloop query="...">)variablescgi,file,url,form,cookie,client
Always prefix to be explicit and avoid scope-bleed bugs. In a large application, an unqualified variable that accidentally resolves from url instead of variables can cause hard-to-trace security issues.
Need to inspect all scope values at once?
ColdFusion has a built-in debugging tool — cfdump. It renders any variable, struct, array, or scope as a formatted HTML table, perfect for exploring what's actually in scope at runtime.
<cfdump var="#variables#" label="variables scope">
<cfdump var="#url#" label="url scope">
<cfdump var="#session#" label="session scope">
Add those lines temporarily to any .cfm file, reload in the browser, and you get a complete view of every variable in each scope. Remove them before going to production.
Need to edit a file? Use vi
If you need to tweak scopes.cfm without rewriting it from scratch:
vi /opt/coldfusion2025/cfusion/wwwroot/scopes.cfm
| Key | What it does |
|---|---|
i | Enter insert mode |
Esc | Back to normal mode |
:wq + Enter | Save and quit |
:q! + Enter | Quit without saving |
When all the checks above are green, this lesson is complete. Your progress is saved automatically — move straight on to the next lesson.
- Previous lesson
- CFML Syntax — Tags and Script
- Next lesson
- Application.cfc & Request Lifecycle